Search code examples
rletter

how can i find specific letter in character in R


there is a vecter

tmp <- c("a", "a.b", "c", "c.g.g", "rr", "r.t")

i want find index or true/false including "."

the result will be 2,4,6 or F T F T F T

how can i do?


Solution

  • You can use grepl and escape the ..

    > tmp <- c("a", "a.b", "c", "c.g.g", "rr", "r.t")
    > grepl("\\.", tmp)
    [1] FALSE  TRUE FALSE  TRUE FALSE  TRUE