Displaying 1 result from an estimated 1 matches for "cars1_unique".
2010 Dec 16
2
Compare two dataframes
...e a better way?
Many thanks for your help,
Mark
#compare two dataframes and extract uncommon rows
#MAKE SOME DATA
cars$id<-paste(cars$speed,cars$dist,sep="") $create unique ID field by
pasting all columns together
cars1<-cars[1:35,]
cars2<-cars[16:50,]
#EXTRACT UNIQUE ROWS
cars1_unique<-cars1[cars1$id %in% setdiff(cars1$id,cars2$id),] #rows
unique to cars1 (i.e., not in cars2)
cars2_unique<-cars2[cars2$id %in% setdiff(cars2$id,cars1$id),] #rows
unique to cars2