Dear all, I have a data.frame like this ID VAR1 11 blaaal 121 blalda 121 adada 234 baada 231 ddaaa 231 baada ... ... and I have another vector of ID, say, c(121,234,231) How could I collect all the observations start with ID from c(121,234,231) ? Thanks All the Best, Desper -- View this message in context: http://www.nabble.com/Making-a-sub-data.frame-tp24687873p24687873.html Sent from the R help mailing list archive at Nabble.com.
Try this:> xID VAR1 1 11 blaaal 2 121 blalda 3 121 adada 4 234 baada 5 231 ddaaa 6 231 baada> idm <- c(121,234,231) > subset(x, ID %in% idm)ID VAR1 2 121 blalda 3 121 adada 4 234 baada 5 231 ddaaa 6 231 baada>On Mon, Jul 27, 2009 at 4:40 PM, desper<idesper at gmail.com> wrote:> > Dear all, > > I have a data.frame like this > > ID ? ? ? ? VAR1 > 11 ? ? ? ? ? blaaal > 121 ? ? ? ? blalda > 121 ? ? ? ? ?adada > 234 ? ? ? ?baada > 231 ? ? ? ? ddaaa > 231 ? ? ? ? baada > ... ? ? ? ? ? ... > > and I have another vector of ID, say, c(121,234,231) > How could I collect all the observations start with ID from c(121,234,231) ? > > > Thanks > > All the Best, > Desper > -- > View this message in context: http://www.nabble.com/Making-a-sub-data.frame-tp24687873p24687873.html > Sent from the R help mailing list archive at Nabble.com. > > ______________________________________________ > R-help at r-project.org mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code. >-- Jim Holtman Cincinnati, OH +1 513 646 9390 What is the problem that you are trying to solve?
Suppose DF is the data frame and someIDs is the vector subDF <- subset(DF, ID %in% someIDs) Bill Venables http://www.cmis.csiro.au/bill.venables/ -----Original Message----- From: r-help-bounces at r-project.org [mailto:r-help-bounces at r-project.org] On Behalf Of desper Sent: Tuesday, 28 July 2009 6:41 AM To: r-help at r-project.org Subject: [R] Making a sub data.frame Dear all, I have a data.frame like this ID VAR1 11 blaaal 121 blalda 121 adada 234 baada 231 ddaaa 231 baada ... ... and I have another vector of ID, say, c(121,234,231) How could I collect all the observations start with ID from c(121,234,231) ? Thanks All the Best, Desper -- View this message in context: http://www.nabble.com/Making-a-sub-data.frame-tp24687873p24687873.html Sent from the R help mailing list archive at Nabble.com. ______________________________________________ R-help at r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.