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
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
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-helpSee ?"%in%" as in nameofdataframe$subject %in% c(19,15) Uwe Ligges
Or
subset(nameofdataset, subject %in% c(15,19))
which does "the right thing" if subject should be missing (unlikely in
this
example I know, but likely to be a different story if conditioning on
concentration, say).
A pity subset() and transform() are not mentioned in the subsetting
section
of the "Introduction to R" manual - a suggestion for future releases?
Simon Fear
Senior Statistician
Syne qua non Ltd
Tel: +44 (0) 1379 644449
Fax: +44 (0) 1379 644445
email: Simon.Fear at synequanon.com
web: http://www.synequanon.com
Number of attachments included with this message: 0
This message (and any associated files) is confidential and\...{{dropped}}