[R] Matching a character in a string

Fabrice DELENTE fdelente at mail.cpod.fr
Mon Jan 25 21:40:39 CET 2010


Hello.

Sorry for this very basic question but I didn't find (of didn't understand)
the answer either in the help or in the online guide.

I have a string, let's say "hello". I want to know if there is some
character in it, let's say an 'o'.

I tried

> charmatch("o", strstplit("hello",""))

but it gives NA (why??)

Thinking it may be a type problem, I tried

> charmatch("o",as.character(strsplit("hello","")))

but it gives NA too (why???)

So how can I know if a given string contains a given char?

Thanks!

-- 
Fabrice DELENTE



More information about the R-help mailing list