I am using R in Ubuntu, and trying to go over list of files, some of them i need and some of them i don\'t need,
I try to get the one\'s i need by finding a sub string
We can use stringi::stri_count
:
library(stringi)
library(purrr)
# simulate some data
set.seed(1492)
(map_chr(1:10, function(i) {
paste0(sample(letters, sample(10:30), replace=TRUE), collapse="")
}) -> strings)
## [1] "jdpcypoizdzvfzs" "gyvcljnfmrzmdmkufq"
## [3] "xqwrmnklbixnccwyaiadrsxn" "bwbenawcwvdevmjfvs"
## [5] "ytzwnpkuromfbklfsdnbwwnlrw" "wclxpzftqgwxyetpsuslgohcdenuj"
## [7] "czkhanefss" "mxsrqrackxvimcxqcqsditrou"
## [9] "ysqshvzjjmwes" "yzawyoqxqxiasensorlenafcbk"
# How many "w"s in each string?
stri_count_regex(strings, "w{1}")
## [1] 0 0 2 3 4 2 0 0 1 1