[R] extracting a sub data frame by value of one of its columns
Prof Brian D Ripley
ripley at stats.ox.ac.uk
Sun May 7 19:22:10 CEST 2000
On Sun, 7 May 2000, Faheem Mitha wrote:
> Dear R people,
>
> This should be a straightforward operation, but I am having difficulties.
> I have a data frame with three columns, call them a, b, and c. c is a
> column of factors, 1...10. I want to extract all the rows for which c has
> the value say 1, and put them in a separate data frame. I looked at the
> various sort functions provided, but see no way to easily adapt them to my
> needs.
Nothing to do with sorting as far as I can see. Try
df2 <- df1[df1$c == 1,]
and note that indexing is pretty central to using S (the language), so it
is worth learning all the ways to use it.
--
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