I observe user
s at different time
s and in different situation
s and potentially I see them multiple times, like so:
df <- data.table(time = c(1,1,1,2,2),
user = c(1,1,2,1,2),
situation = c(1,1,1,2,2),
observation = c(1,2,1,1,1))
What I would like to do is to count the number of user
-situation
s in each time period using data.table
. Expected output:
result <- data.table(time = c(1,2),
user_situations = c(2,2))
I know I can do this in a chained way:
unique(df[, .(time, user, situation)])[, .(user_situations = .N), .(time)]
but wonder if there's a simple way to do this in one go.