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
It looks like you're after strings with one a
and no more, regardless where in the string. While stringi
can accomplish the task, a base solution would be:
s <- c("a", "aa", "aca", "", "b", "ba", "ab")
m <- gregexpr("a", s)
s[lengths(regmatches(s, m)) == 1]
[1] "a" "ba" "ab"
Alternatively, a regex-lite approach:
s[vapply(strsplit(s, ""), function(x) sum(x == "a") == 1, logical(1))]
[1] "a" "ba" "ab"