I'm trying to get the top row by a group of three variables using a data.table.
I have a working solution:
col1 <- c(1,1,1,1,2,2,2,2,3,3,3,3)
col2 <- c(2000,2000,2001,2001,2000,2000,2001,2001,2000,2000,2001,2001)
col4 <- c(1,2,3,4,5,6,7,8,9,10,11,12)
data <- data.frame(store=col1,year=col2,month=12,sales=col4)
solution1 <- data.table(data)[,.SD[1,],by="store,year,month"]
I used the slower approach suggested by Matthew Dowle in the following link:
I'm trying to implement the faster self join but cannot get it to work.
Does anyone have any suggestions?