Hi I have two dataframes names(DF1) = c("id", "val1", "val2"); names(DF2) = c("id2"); Ids in DF2 are a complete subset of those in DF1 How can I extract entries from DF1 where id NOT IN DF2. I tried setdiff(DF1, DF2); setdiff(DF1$id, DF2$id), etc. Although the latter eliminates the ids as required, I dont know how to extract val1 and val2 for the resultant set. Thanks Lalitha ____________________________________________________________________________________ 8:00? 8:25? 8:40? Find a flick in no time
try something along these lines (untested): DF1[DF1$id %in% DF2$id2, c("val1", "val2")] DF1[!DF1$id %in% DF2$id2, c("val1", "val2")] I hope it helps. Best, Dimitris ---- Dimitris Rizopoulos Ph.D. Student Biostatistical Centre School of Public Health Catholic University of Leuven Address: Kapucijnenvoer 35, Leuven, Belgium Tel: +32/(0)16/336899 Fax: +32/(0)16/337015 Web: http://med.kuleuven.be/biostat/ http://www.student.kuleuven.be/~m0390867/dimitris.htm Quoting lalitha viswanath <lalithaviswanath at yahoo.com>:> Hi > I have two dataframes > names(DF1) = c("id", "val1", "val2"); > > names(DF2) = c("id2"); > > Ids in DF2 are a complete subset of those in DF1 > > How can I extract entries from DF1 where id NOT IN > DF2. > > I tried setdiff(DF1, DF2); setdiff(DF1$id, DF2$id), > etc. > Although the latter eliminates the ids as required, I > dont know how to extract val1 and val2 for the > resultant set. > > > Thanks > Lalitha > > > > ____________________________________________________________________________________ > 8:00? 8:25? 8:40? Find a flick in no time > > ______________________________________________ > R-help at stat.math.ethz.ch 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. > >Disclaimer: http://www.kuleuven.be/cwis/email_disclaimer.htm
names(DF1)[ !(names(DF1) %in% names(DF2)) ] To illustrate:> x <- letters[1:5] > y <- letters[c(2,4)] > x[ !(x %in% y) ][1] "a" "c" "e" At 11:41 AM -0800 3/7/07, lalitha viswanath wrote:>Hi >I have two dataframes >names(DF1) = c("id", "val1", "val2"); > >names(DF2) = c("id2"); > >Ids in DF2 are a complete subset of those in DF1 > >How can I extract entries from DF1 where id NOT IN >DF2. > >I tried setdiff(DF1, DF2); setdiff(DF1$id, DF2$id), >etc. >Although the latter eliminates the ids as required, I >dont know how to extract val1 and val2 for the >resultant set. > > >Thanks >Lalitha > > > >____________________________________________________________________________________ >8:00? 8:25? 8:40? Find a flick in no time > >______________________________________________ >R-help at stat.math.ethz.ch 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.-- -------------------------------------- Don MacQueen Environmental Protection Department Lawrence Livermore National Laboratory Livermore, CA, USA