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
)
I want to count the unique values of the combination of iso
, and year
(which would be NLD 2009
, AUS 2011
, NLD 2008
and AUS 2012
, so 4.
I tried df1[,uniqueN(.(iso, year))]
and df1[,uniqueN(c("iso", "year"))]
The first one gives an error, and the second one gives the answer 2, where I am looking for 4 unique combinations.
What am I doing wrong here?
(as I am doing this with a big dataset of strings, I would prefer no to combine the columns, then test).