Dear all, I have a string and I want to search for its existance inside a data.frame (or in a column of the data.frame). One way is for me to do this manually: Make a for loop for the number of elements and compare one by one element. Is there though any more improved way to do that? B.R Alex [[alternative HTML version deleted]]
Hi> > Dear all, > I have a string and I want to search for its existance inside adata.frame> (or in a column of the data.frame). > > One way is for me to do this manually: Make a for loop for the number of> elements and compare one by one element. Is there though any moreimproved> way to do that?Rather vague question. What kind of string? Shall it be matched fully? sapply(your.data.frame, match, "your.string", nomatch=0) gives you a result 1 where it matches the string and 0 where not. Regards Petr> > B.R > Alex > > [[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 guidehttp://www.R-project.org/posting-guide.html> and provide commented, minimal, self-contained, reproducible code.
On 21.12.2011 09:49, Alaios wrote:> Dear all, > I have a string and I want to search for its existance inside a data.frame (or in a column of the data.frame). > > One way is for me to do this manually: Make a for loop for the number of elements and compare one by one element. Is there though any more improved way to do that?Yes: you can also compare the whole column at once, but since there is no example in your message, you probably don't expect a detailed answer. Best, Uwe Ligges> > B.R > Alex > > [[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.