Re: [R] subsetting by rows

2011-08-31 Thread Jorge I Velez
Hi Joao, Here is one way (d is your data set): d[apply(d == 'P', 1, any),] HTH, Jorge On Wed, Aug 31, 2011 at 1:28 PM, Joao Fadista <> wrote: > Dear all, > > I would like to know how to subset a data.frame by rows. > > Example: > > Probesets34884348883489

Re: [R] subsetting by rows

2011-08-31 Thread Patrick Burns
If your data frame is called 'df', then something like the following should work: df[ apply(as.matrix(df[,-1]), 1, function(x) any(x == "P")), ] This creates a logical vector as long as the number of rows. As Bill Dunlap recently noted, 'apply' really wants a matrix and not a data frame. On 31

Re: [R] subsetting by rows

2011-08-31 Thread R. Michael Weylandt
Suppose your data is called df. df[rowSums(df == "P")>0,] In short, this tests each element for equality for "P", sums the number of "P"s found and subsets when that number is >0. Michael On Wed, Aug 31, 2011 at 1:28 PM, Joao Fadista wrote: > Dear all, > > I would like to know how to subset a

[R] subsetting by rows

2011-08-31 Thread Joao Fadista
Dear all, I would like to know how to subset a data.frame by rows. Example: Probesets348843488834892 1 19676_at A AA 2 10001_atP P P 3 10002_at