[R] selecting data from a data.frame?
Prof Brian Ripley
ripley at stats.ox.ac.uk
Fri Jan 4 22:44:00 CET 2002
On 4 Jan 2002, Michael A. Miller wrote:
> I know how to plot a subset of a data.frame by doing something
> like
>
> > plot( mydata$x[y>2] )
>
> Is there a way to do something similar for an entire data.frame?
> For example, I can do this something like
>
> > lm( x[y>2] ~ type[y>2], data=mydata )
>
> but I'm a lazy typist, so I'd like to be able to do something
> like
>
> > lm( x ~ type, data=mydata[y>2] )
>
> Is there a way to select rows from a data frame like that?
That will work if done correctly as mydata[y>2, ], but
lm(x ~ type, data=mydata, subset = (y>2))
is better style, especially as it allows y to be a column of mydata.
--
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
mailing list