[R] problem with comparing a part of string with whole string

Daniel Malter daniel at umd.edu
Fri Feb 20 19:28:46 CET 2009


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:

> Hi
>
> r-help-bounces at r-project.org napsal dne 19.02.2009 13:39:42:
>
> > Hi all,
> >
> > I got one problem with comparing strings like if any string is like
> >
> > "*RIGHT, EPICARDIUM: FOCUS, GRAY-WHITE, SINGLE, APPROX 0.6 CM IN
> DIAMETER*."
> >
> > and i have to compare       "*GRAY-WHITE*"        with the above string
> >
> > or otherwise   i have to compare       " *TUMOR BENIGN*"       this
> string
> > with
> >
> > "*MEDULLRY TUMOR BENIGN,TYP PHEOCHROMOCYTOMA*"
> >
> > i tried with split and compare but its not working
>
> Work for regular expressions?
>
> vec="*RIGHT, EPICARDIUM: FOCUS, GRAY-WHITE, SINGLE, APPROX 0.6 CM IN 
> DIAMETER*."
> test="GRAY-WHITE"
> regexpr(test, vec)
> [1] 28
> attr(,"match.length")
> [1] 10
>
> Regards
> Petr
>
>
> >
> > can any one suggest how can i compare these type of Strings
> >
> > thanks in advance
> >
>  >    [[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<http://www.r-project.org/p
> osting-guide.html>
> > and provide commented, minimal, self-contained, reproducible code.
>
>




More information about the R-help mailing list