[R] filter data frames
ripley at stats.ox.ac.uk
Fri Jun 7 11:55:30 CEST 2002
On Fri, 7 Jun 2002, Christophe Weibel wrote:
> I'm looking for an easy way to filter data frames.
> Some rows in my data frame needs to be left out,
> for instance, rows with invalid data.
> Right now, if I want to pair two columns of this data frame,
> I have to do this:
> > pairs(as.data.frame(list(tstart=df$tstart[valid],tend=df$tend.sdr[valid])))
> or this:
> > pairs(cbind(df$tstart,df$tend)[valid,],labels=c("tstart","tend"))
> where 'valid' is a logical vector of valid rows.
> Is there a way to filter a data frame without making a vector of
> the columns, thus losing the column names?
> Okay, perhaps I'm greedy. It's already working, what am I complaining
What's wrong with df[valid, c("tstart","tend")], which is what you appear
I am sure that's in the R Introduction.
Brian D. Ripley, ripley at stats.ox.ac.uk
Professor of Applied Statistics, http://www.stats.ox.ac.uk/~ripley/
University of Oxford, Tel: +44 1865 272861 (self)
1 South Parks Road, +44 1865 272860 (secr)
Oxford OX1 3TG, UK Fax: +44 1865 272595
r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html
Send "info", "help", or "[un]subscribe"
(in the "body", not the subject !) To: r-help-request at stat.math.ethz.ch
More information about the R-help