Skip to content
Prev 171226 / 398506 Next

problem with comparing a part of string with whole string

Imagine the following data of noises that people make, and you want to know
who makes the noise "blub."

data=data.frame(rbind(c("blah, boo, blub"),c("blabber, baeh,
blib"),c("quack, cheer, blub")))
names(data)=c("noises")
data

searchTerm="blub"

#The first gives a list of all noises that people make
#who also make the "blub" noise (among others)
data$sound[grep(searchTerm,data$noises)]

# This gives the index (row) number of the observation  
# of who makes the "blub" noise
which(data$noises==data$noises[grep(searchTerm,data$noises)])

Is that what you want?
Daniel


-------------------------
cuncta stricte discussurus
-------------------------

-----Urspr?ngliche Nachricht-----
Von: r-help-bounces at r-project.org [mailto:r-help-bounces at r-project.org] Im
Auftrag von venkata kirankumar
Gesendet: Friday, February 20, 2009 1:20 AM
An: Petr PIKAL
Cc: r-help at r-project.org
Betreff: Re: [R] problem with comparing a part of string with whole string

Hi ,

i just attached one file to this mail which contains one modal of my data
and there i have to search for the rows which contains   "SPECIMENTYP %in%
"ADIPOSE TISSUE""
and the rows which contains     " "PRESERVED"    in  ORGCHARRES
for that i tried with
" r<-subset(rr,SPECIMENTYP %in% "ADIPOSE TISSUE" & grep("IN
DIAMETER",rr$ORGCHARRES),select=c(SPECIMENTYP,ORGCHARRES))"

but i got only the rows having  "ADIPOSE TISSUE"   in  "SPECIMENTYP"

can anyone suggest any of the way for comparision of this type


thanks in advance
On Thu, Feb 19, 2009 at 6:26 PM, Petr PIKAL <petr.pikal at precheza.cz> wrote: