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
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
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
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-
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
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
6 matches
Mail list logo