hi, everybody, my question is: suppose I have two data sets, set A is large and have variables like ID, Gender, Income. Set B is small and suppose only has ID. Now I want to get a subset from data set A which contains ID from Set B. How to do this in R>? Is there any commands to do this? Thank you [[alternative HTML version deleted]]
Take a look at ?merge for doing such join operations. (I believe that should help) If you had provided a sample of your datasets using dput, I would have checked that for you. -----Original Message----- From: r-help-bounces at r-project.org [mailto:r-help-bounces at r-project.org] On Behalf Of song song Sent: 02 November 2010 11:44 To: r-help at r-project.org Subject: [R] how to compare two datasets in R>? hi, everybody, my question is: suppose I have two data sets, set A is large and have variables like ID, Gender, Income. Set B is small and suppose only has ID. Now I want to get a subset from data set A which contains ID from Set B. How to do this in R>? Is there any commands to do this? Thank you [[alternative HTML version deleted]] ______________________________________________ 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.
On Nov 2, 2010, at 2:14 AM, song song wrote:> hi, everybody, my question is: > > suppose I have two data sets, set A is large and have variables like > ID, > Gender, Income. Set B is small and suppose only has ID. > > Now I want to get a subset from data set A which contains ID from > Set B.Try: A[A$ID %in% B$ID, ] Or: subset(A, ID %in% B$ID)> > How to do this in R>? Is there any commands to do this? > > Thank you > > [[alternative HTML version deleted]]-- David Winsemius, MD West Hartford, CT