I would like to keep a certain number of rows per variable: For example assuming I have the following data set (the actual data set is rather large):
part<-c(1,1,1,2,2,2,3,3)
choice<-c(6,7,15,42,1,1,4,5)
data<-cbind(part,choice)
des_data<-data[c(1,2,4,5,7,8),]
part choice
[1,] 1 6
[2,] 1 7
[3,] 1 15
[4,] 2 42
[5,] 2 1
[6,] 2 1
[7,] 3 4
[8,] 3 5
I would like to keep only the first 2 observations per "part"(icipant).
So that the final data looks like this:
part choice
[1,] 1 6
[2,] 1 7
[3,] 2 42
[4,] 2 1
[5,] 3 4
[6,] 3 5
How can I do it?
Thanks!