-2

My goal is to split a df such that row 1-21 is one data frame, and row 22-39 make up another data frame. I can't find how to do that anywhere.Thanks!

2 Answers2

0

You can use split using data.table. Assuming you want a more general version of your problem (where you bundle together every 20 observations)

library(data.table)
setDT(df)
split(df, by = floor(1:nrow(df)/20))
linog
  • 5,350
  • 3
  • 13
  • 23
0

You can split data frames by selecting just the rows or the columns that you need and associating them to a new object:

new_df1 <- df[1:21, ]

new_df2 <- df[22:39, ]
Greg
  • 3,398
  • 5
  • 15
  • 29