I have a data.table as follows:
library(data.table)
library(haven)
df1 <- fread(
"A B C iso year
0 B 1 NLD 2009
1 A 2 NLD 2009
0 Y 3 AUS 2011
1 Q 4 AUS 2011
0 NA 7 NLD 2008
1 0 1 NLD 2008
0 1 3 AUS 2012",
header = TRUE
)
Now with the following data.table I have simply removed two lines:
df2 <- fread(
"A B C iso year
0 B 1 NLD 2009
0 Y 3 AUS 2011
1 Q 4 AUS 2011
0 NA 7 NLD 2008
1 0 1 NLD 2008",
header = TRUE
)
What I want, is to figure out, what unique values have been removed. For example, below I have removed two lines, but only one value that was unique in df1
:
df1[, uniqueN(.SD), .SDcols=c("iso", "year")] # 4
df2[, uniqueN(.SD), .SDcols=c("iso", "year")] # 3
What I want is to extract the unique value that was removed from df1
. Desired answer:
AUS 2012
I have a feeling this is quite a difficult question (or hopefully, I am missing something obvious). But perhaps someone can get me on the right track..