data=data.table("Student"=c(1,1,1,1,1,2,2,3,3,3,4,4,5,5,5,5,5),
"X1"=c(0,0,1,1,1,0,2,0,0,2,0,1,0,0,0,1,2))
I wish to count three objects.
First I wish to count how many Student have an 1 in the X1 column.
Second I wish to count how many Student have 2 in the X1 column before a 1.
Three I wish to count how many Student have 2 in the X1 column after a 1.
I seek data.table solution