Hello, it is not clear to me, how to search if in a string there is a "." (full stop). Using: grepl(".",string) doesn't work because the full stop it is a metacharacter (it gives "TRUE" also if no full stop is in the character). I tried also to insert \. but it does not work.> grepl("\.",string)Error: '\.' is an unrecognized escape in character string starting "\." Thank you very much for your help Francesco [[alternative HTML version deleted]]
On 13-05-13 4:19 AM, Francesco Isotta wrote:> Hello, > it is not clear to me, how to search if in a string there is a "." (full > stop). > Using: > > grepl(".",string) > > doesn't work because the full stop it is a metacharacter (it gives "TRUE" > also if no full stop is in the character).Use grepl(".", string, fixed=TRUE). I tried also to insert \. but it> does not work.You did not insert \., because you'd need to escape the backslash to do that. grepl("\\.", string) would work. Duncan Murdoch> >> grepl("\.",string) > Error: '\.' is an unrecognized escape in character string starting "\." > > Thank you very much for your help > > Francesco > > [[alternative HTML version deleted]] > > ______________________________________________ > R-help at r-project.org mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code. >
You may also try: grepl("[.]",c("ad.1","ads","ad.2")) #[1]? TRUE FALSE? TRUE A.K. ----- Original Message ----- From: Francesco Isotta <isottaf at hotmail.com> To: r-help at r-project.org Cc: Sent: Monday, May 13, 2013 4:19 AM Subject: [R] grepl Hello, it is not clear to me, how to search if in a string there is a "." (full stop). Using: grepl(".",string) doesn't work because the full stop it is a metacharacter (it gives "TRUE" also if no full stop is in the character). I tried also to insert \. but it does not work.> grepl("\.",string)Error: '\.' is an unrecognized escape in character string starting "\." Thank you very much for your help Francesco ??? [[alternative HTML version deleted]] ______________________________________________ R-help at r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.