I have a data frame like this
ID <- c(1)
Rank <- c(1,2,3,1,2)
Val <- c(10,20,30,40,50)
df <- data.frame(ID,Rank,Val)
df
ID Rank Val
1 1 1 10
2 1 2 20
3 1 3 30
4 1 1 40
5 1 2 50
Within each ID, how to subset the dataframe such that I have two different frames
df1:
ID Rank Val
1 1 1 10
2 1 2 20
3 1 3 30
df2:
ID Rank Val
4 1 1 40
5 1 2 50
The total length of each ID could vary. Hence sometimes I could have rank like 1,2,1,2
. In this case, the two frames will be (1,2) and (1,2)