Re: [R] grep with search terms defined by a variable

2010-08-04 Thread Amos Folarin
You might also find match and pmatch of use here. On Aug 3, 2010, at 12:05 AM, Daniel Malter wrote: > > Hi, I have a good grasp of grep() and gsub() for finding and > extracting > character strings. However, I cannot figure out how to use a search > term > that is stored in a

Re: [R] grep with search terms defined by a variable

2010-08-03 Thread David Winsemius
On Aug 3, 2010, at 12:05 AM, Daniel Malter wrote: Hi, I have a good grasp of grep() and gsub() for finding and extracting character strings. However, I cannot figure out how to use a search term that is stored in a variable when the search string is more complex. #Say I have a string, an

Re: [R] grep with search terms defined by a variable

2010-08-02 Thread Matt Shotwell
Daniel, If you want to search for each term at the beginning of a sting, using the regular expression construct '^', you might use the following > search.terms <- c("Emil", "Meryl") > names <- c("Emil Jannings", +"Charles Chaplin", +"Katherine Hepburn", +"M

Re: [R] grep with search terms defined by a variable

2010-08-02 Thread Daniel Malter
A beauty. Works a charm. Many many thanks. Daniel -- View this message in context: http://r.789695.n4.nabble.com/grep-with-search-terms-defined-by-a-variable-tp2311294p2311307.html Sent from the R help mailing list archive at Nabble.com. __ R-help@r-

Re: [R] grep with search terms defined by a variable

2010-08-02 Thread Joshua Wiley
Hi Daniel, What about this? # my.names <- c("Emil Jannings", "Charles Chaplin", "Katherine Hepburn", "Meryl Streep") search.term <- c("Emil", "Meryl") for(i in 1:length(search.term)){ print(grep(paste("^", search.term, sep="")[i], my.names)) } ## Chee

[R] grep with search terms defined by a variable

2010-08-02 Thread Daniel Malter
Hi, I have a good grasp of grep() and gsub() for finding and extracting character strings. However, I cannot figure out how to use a search term that is stored in a variable when the search string is more complex. #Say I have a string, and want to know whether the last name "Jannings" is in the s