[R] Subsetting a dataframe

Uwe Ligges ligges at statistik.uni-dortmund.de
Tue Aug 26 09:03:15 CEST 2003


a0203664 at unet.univie.ac.at wrote:

> Hi R-people
> 
> I have a question concerning subsetting. I have a dataframe which contains among other variables the variable "subject". For each subject number there are several rows, e.g.:
> subject  treatment concentration day
> 19          a          15,4       1
> 19          a          18,3       2
> 19          a           2,3       3
> 
> etc.
> 
> Im trying to subset the dataframe to get for example only the rows of subject 19 and subject 15. I tried this with
> 
>         nameofdataframe[nameofdataframe$subject==c(19,15),]
> 
> This doesnt work as i get less rows than i should and a warning as well. How can i succeed doing this?
> 
> Thanks a lot
> 
> Gabi
> 
> ______________________________________________
> R-help at stat.math.ethz.ch mailing list
> https://www.stat.math.ethz.ch/mailman/listinfo/r-help


See ?"%in%"

as in

  nameofdataframe$subject %in% c(19,15)

Uwe Ligges




More information about the R-help mailing list