[R] sub data frame by expression

Prof Brian Ripley ripley at stats.ox.ac.uk
Fri Oct 17 12:37:52 CEST 2003


On Fri, 17 Oct 2003 Arne.Muller at aventis.com wrote:

> I've the following data frame with 54 rows and 4 colums:
> 
> > x                  
>                   Ratio  Dose Time Batch
> R.010mM.04h.NEW    0.02 010mM  04h   NEW
> R.010mM.04h.NEW.1  0.07 010mM  04h   NEW
> ...
> R.010mM.24h.NEW.2  0.06 010mM  24h   NEW
> R.010mM.04h.OLD    0.19 010mM  04h   OLD
> ...
> R.010mM.04h.OLD.1  0.49 010mM  04h   OLD
> R.100mM.24h.OLD    0.40 100mM  24h   OLD
> 
> I'd like to create a sub data frame containing all rows where Batch == "OLD"
> and keeping the 4 colums. Assume that I don't know the order of the rows
> (otherwise I could just do something like x[1:20,]).
> 
> I've tried x[x$Batch == 'OLD'] or x[x[,4] == 'OLD'] but it generates errors.

That subsets columns, not rows. Try x[x$Batch == "OLD",]

-- 
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 272866 (PA)
Oxford OX1 3TG, UK                Fax:  +44 1865 272595




More information about the R-help mailing list