I am trying to return an index for a data set by searching using filenames.
The name may be ANG_AUT.N.0734C70411A-1_1sA_0734C70411A.fasta, but i'd just
like to search it using the term "0734C70411" as the file may be
0734C70411A or 0734C70411C or 0734C70411D
Any way to do this other than doing something like this. where 0734C70411A
is part of matrix list[,8]
samp=paste("ANG_AUT.N.",list[i,8],"-1_1sA_",list[i,8],".fasta",sep="")
data[which(data[,2]==samp),]
This is similar to the =~/ / function in perl.
Thanks
--
View this message in context:
http://r.789695.n4.nabble.com/How-to-find-data-that-includes-certain-values-tp3230161p3230161.html
Sent from the R help mailing list archive at Nabble.com.
There are several pattern matching functions that will solve your problem:
grep regexpr
do RSiteSearch("pattern match")
On Fri, Jan 21, 2011 at 12:26 PM, poppinkid <jtlu at bcm.edu>
wrote:>
> I am trying to return an index for a data set by searching using filenames.
>
> The name may be ANG_AUT.N.0734C70411A-1_1sA_0734C70411A.fasta, but i'd
just
> like to search it using the term "0734C70411" ?as the file may be
> 0734C70411A or 0734C70411C or 0734C70411D
>
> Any way to do this other than doing something like this. ?where 0734C70411A
> is part of matrix list[,8]
>
>
samp=paste("ANG_AUT.N.",list[i,8],"-1_1sA_",list[i,8],".fasta",sep="")
> data[which(data[,2]==samp),]
>
> This is similar to the =~/ / function in perl.
>
>
> Thanks
> --
> View this message in context:
http://r.789695.n4.nabble.com/How-to-find-data-that-includes-certain-values-tp3230161p3230161.html
> Sent from the R help mailing list archive at Nabble.com.
>
> ______________________________________________
> 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
> and provide commented, minimal, self-contained, reproducible code.
>
--
Jim Holtman
Data Munger Guru
What is the problem that you are trying to solve?
Henrique Dallazuanna
2011-Jan-21 20:38 UTC
[R] How to find data that includes certain values
Take a look on grep function. On Fri, Jan 21, 2011 at 3:26 PM, poppinkid <jtlu@bcm.edu> wrote:> > I am trying to return an index for a data set by searching using filenames. > > The name may be ANG_AUT.N.0734C70411A-1_1sA_0734C70411A.fasta, but i'd just > like to search it using the term "0734C70411" as the file may be > 0734C70411A or 0734C70411C or 0734C70411D > > Any way to do this other than doing something like this. where 0734C70411A > is part of matrix list[,8] > > samp=paste("ANG_AUT.N.",list[i,8],"-1_1sA_",list[i,8],".fasta",sep="") > data[which(data[,2]==samp),] > > This is similar to the =~/ / function in perl. > > > Thanks > -- > View this message in context: > http://r.789695.n4.nabble.com/How-to-find-data-that-includes-certain-values-tp3230161p3230161.html > Sent from the R help mailing list archive at Nabble.com. > > ______________________________________________ > R-help@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 > and provide commented, minimal, self-contained, reproducible code. >-- Henrique Dallazuanna Curitiba-Paraná-Brasil 25° 25' 40" S 49° 16' 22" O [[alternative HTML version deleted]]
Hello
Consider following dataframe named df
var1 var2 var3
3771 354 565
654654 963 6677
775 147 657754
df <- read.table('clipboard', header = TRUE)
df
#find indexes with '77' in var 1
myIndexes <- grep( glob2rx("*77*"), df$var1)
myIndexes
#find actual values of seach above
myValu <- grep( glob2rx("*77*"), df$var1, value=TRUE)
myValu
#find all '77' in entire dataframe
all77 <- lapply(df, function(x)grep( glob2rx("*77*"), x,
value=TRUE))
all77
#OR indexes
all77ind <-lapply(df, function(x)grep( glob2rx("*77*"), x))
all77ind
Hope that helps
With best regards
Denis