I'm working on a data.table that includes X and Y columns and I want to create a new column Z which is the number of all records with the same value of (X, Y).
I know the syntax when working with a data.frame:
ddply(df,.(X,Y),nrow)
I tested different syntaxes I found on this forum but they didn't work:
dt[, Z := lapply(.SD,nrow), by="X,Y"] # or
dt[, `:=`(Z = lapply(.SD,nrow)), by="X,Y"]
I precise X and Y are numeric.
Starting from
The appropriate syntax is
or