intersection - un-intersect values in R -


i have 2 data sets of @ least 420,500 observations each, e.g.

dataset1 <- data.frame(col1=c("microsoft","apple","vmware","delta","microsoft"),                      col2=paste0(c("a","b","c",4,"asd"),".exe"),                      col3=rnorm(5))  dataset2 <- data.frame(col1=c("apple","cisco","proactive","dtex","microsoft"),                      col2=paste0(c("a","b","c",4,"asd"),".exe"),                      col3=rnorm(5)) > dataset1        col1    col2 col3 1 microsoft   a.exe    2 2     apple   b.exe    1 3    vmware   c.exe    3 4     delta   4.exe    4 5 microsoft asd.exe    5 > dataset2        col1    col2 col3 1     apple   a.exe    3 2     cisco   b.exe    4 3    vmware   d.exe    1 4     delta   5.exe    5 5 microsoft asd.exe    2 

i print observations in dataset1 do not intersect 1 in dataset2 (comparing both col1 , col2 in each), in case print except last observation - observations 1 & 2 match on col2 not col1 , observation 3 & 4 match on col1 not col2, i.e.:

        col1  col2 col3  1:     apple b.exe    1  2:     delta 4.exe    4  3: microsoft a.exe    2  4:    vmware c.exe    3  

you use anti_join dplyr

 library(dplyr)  anti_join(df1, df2, = c('col1', 'col2'))  #      col1  col2       col3  #1     delta 4.exe -0.5836272  #2    vmware c.exe  0.4196231  #3     apple b.exe  0.5365853  #4 microsoft a.exe -0.5458808 

data

 set.seed(24)  df1 <- data.frame(col1 = c('microsoft', 'apple', 'vmware', 'delta',   'microsoft'), col2= c('a.exe', 'b.exe', 'c.exe', '4.exe', 'asd.exe'),      col3=rnorm(5), stringsasfactors=false)  set.seed(22)  df2 <- data.frame(col1 = c( 'apple', 'cisco', 'proactive', 'dtex',   'microsoft'), col2= c('a.exe', 'b.exe', 'c.exe', '4.exe', 'asd.exe'),    col3=rnorm(5), stringsasfactors=false) 

Comments

Popular posts from this blog

javascript - Using jquery append to add option values into a select element not working -

Android soft keyboard reverts to default keyboard on orientation change -

Rendering JButton to get the JCheckBox behavior in a JTable by using images does not update my table -