[R] dataframe subset using levels as criteria
Prof Brian Ripley
ripley at stats.ox.ac.uk
Wed Jan 30 16:03:16 CET 2002
On 30 Jan 2002, Ernesto Jardim wrote:
> Hi
>
> I want to select a subset of a dataframe (frota) using the levels of a
> factor (matricula) in another dataframe (logbooks.eda).
>
> The command and output are bellow and it's not working ...
>
> > frota[frota$matricula==levels(logbooks.eda$matricula),]
> matricula compff tab potmaq
> 1 A-1420-C NA NA NA
> 2 A-1676-C NA 12070 36800
> 3 A-1954-C 3214 17565 44100
> 4 A-1961-C 3197 17992 46300
> 5 A-2011-C 3198 17184 46300
> Warning messages:
> 1: longer object length
> is not a multiple of shorter object length in: is.na(e1) | is.na(e2)
> 2: longer object length
> is not a multiple of shorter object length in:
> "==.default"(frota$matricula, levels(logbooks.eda$matricula))
>
> Can someone help me with this ?
Use %in% and not ==. == matches cyclically along the shorter vector, and
I presume you want all cases matching any of the levels.
--
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