Say I have a large data frame in long format, with each subject occupying 5 rows, with 5 subjects in total.
x=c(1,1,1,1,1,2,2,2,2,2,3,3,3,3,3,4,4,4,4,4,5,5,5,5,5)
df=data.frame(x, 1:25)
Now I want to separate this into 5 separate data frames, one for each subject. I know I could do this:
s01=df[df$x==1,]
5 times, but I want to create all five data frames in one go, using one command. Is there a way to do this (e.g. with a for loop or something like lapply)? I tried with a for loop but not sure how to get it to output 5 separate objects with different names.