determine frequency of string using grep [duplicate]
问题 This question already has an answer here : How to get frequency of word in a sentence in R? (1 answer) Closed 6 years ago . if I have a vector x <- c("ajjss","acdjfkj","auyjyjjksjj") and do: y <- x[grep("jj",x)] table(y) I get: y ajjss auyjyjjksjj 1 1 However the second string "auyjyjjksjj" should count the substring "jj" twice. How can I change this from a true/false computation, to actually counting the frequency of "jj"? Also if for each string the frequency of the substring divided by the