Re: [R] text matching

2011-09-20 Thread Takatsugu Kobayashi
Hi, The "str_locate" function instringr package may do what you are looking for. Hope this link will help... http://en.wikibooks.org/wiki/R_Programming/Text_Processing Taka On Mon, Sep 19, 2011 at 7:15 PM, SNV Krishna wrote: > Hi All, > > I have a character vector by name tickers > >> head(ti

Re: [R] text matching

2011-09-19 Thread SNV Krishna
rom: David Winsemius [mailto:dwinsem...@comcast.net] Sent: Monday, September 19, 2011 10:10 PM To: Sarah Goslee Cc: SNV Krishna; r-help@r-project.org Subject: Re: [R] text matching On Sep 19, 2011, at 7:05 AM, Sarah Goslee wrote: > Hi, > > On Mon, Sep 19, 2011 at 6:15 AM, SNV Krishna >

Re: [R] text matching

2011-09-19 Thread David Winsemius
On Sep 19, 2011, at 7:05 AM, Sarah Goslee wrote: Hi, On Mon, Sep 19, 2011 at 6:15 AM, SNV Krishna wrote: Hi All, I have a character vector by name tickers head(tickers,10) V1 1 ADARSHPL.BO 2AGR.V 3 AGU 4 AGU.TO 5 AIMCO.BO 6 ALUFLUOR.BO 7

Re: [R] text matching

2011-09-19 Thread Sarah Goslee
Hi, On Mon, Sep 19, 2011 at 6:15 AM, SNV Krishna wrote: > Hi All, > > I have a character vector by name tickers > >> head(tickers,10) > >            V1 > 1  ADARSHPL.BO > 2        AGR.V > 3          AGU > 4       AGU.TO > 5     AIMCO.BO > 6  ALUFLUOR.BO > 7        AMZ.V > 8          AVD > 9  ANIL

Re: [R] text matching and substitution

2009-03-28 Thread Wacek Kusnierczyk
Stephan Kolassa wrote: > Hi Simeon, > > I played around a little with Vectorize and mapply, but I couldn't > make it work :-( So, my best guess would be a simple loop like this: > > result <- as.character(paste(letters,colours(),"stuff",LETTERS)) > target <- c("red","blue","green","gray") > for ( n

Re: [R] text matching and substitution

2009-03-28 Thread baptiste auguie
yet another attempt, colours <- as.character(paste(letters,colours(),"stuff",LETTERS)) target <- c("red","blue","green","gray") matches <- melt(sapply(target, grep, x=colours)) colours[matches$value] <- matches$L1 (probably a worse idea than a straight for loop, though) baptiste On 2

Re: [R] text matching and substitution

2009-03-28 Thread simeon duckworth
Jim/Stephan - absolutely perfect. thank you. very grateful for your help. simeon On Sat, Mar 28, 2009 at 5:27 PM, jim holtman wrote: > Does this do what you want: > > > x <- c('xxxredxxx', 'blue', 'xx', 'greenbluered') > > pat <- 'red|green|blue' > > result <- sub(paste("^.*?(",

Re: [R] text matching and substitution

2009-03-28 Thread jim holtman
Does this do what you want: > x <- c('xxxredxxx', 'blue', 'xx', 'greenbluered') > pat <- 'red|green|blue' > result <- sub(paste("^.*?(", pat, ").*", sep=""), "\\1", x) > # check if no match in original string; replace with 'other' > match <- grep(pat, x) > result[-match] <- 'other' > r

Re: [R] text matching and substitution

2009-03-28 Thread Stephan Kolassa
Hi Simeon, I played around a little with Vectorize and mapply, but I couldn't make it work :-( So, my best guess would be a simple loop like this: result <- as.character(paste(letters,colours(),"stuff",LETTERS)) target <- c("red","blue","green","gray") for ( new.color in target ) { result[grep

Re: [R] text matching and substitution

2009-03-28 Thread Stephan Kolassa
Hi Simeon, I'm slightly unclear on what exactly you are trying to achieve... Are you trying to replace every entry of colours which *contains* "red" by "red", dropping the rest of the entry? And same with "blue"? A short example "before & after" would be helpful... Best, Stephan simeon duc

Re: [R] text matching and substitution

2009-03-28 Thread simeon duckworth
thanks stephan. i'd been trying to make gsub work, but couldnt make it replace the whole expression. so i'd resorted to trying to loop with grep - but with two problems. firstly, i cant seem to make the loop 'remember' the substitutions it makes (see below). secondly, it feels like this is a r

Re: [R] text matching and substitution

2009-03-28 Thread Stephan Kolassa
Hi Simeon, ?gsub HTH, Stephan simeon duckworth schrieb: I am trying to simplify a text variable by matching and replacing it with a string in another vector so for example in colours <- paste(letters,colours(),"stuff",LETTERS) find and replace with ("red","blue","green","gray","yellow","othe