Rokmc1050
Rokmc1050

Reputation: 463

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?

Upvotes: 2

Views: 1125

Answers (2)

jdharrison
jdharrison

Reputation: 30435

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

Upvotes: 4

James Trimble
James Trimble

Reputation: 1866

You could use grep:

grep(".", tmp, fixed=TRUE)

Upvotes: 2

Related Questions