I need to split a dataframe into 17,872 dataframes based on a header-row reoccuring in the dataframe. I need to store the newly created dataframes in a list.
My dataframe looks like:
0 1 2
. . . .
. . . .
. . . .
. . . .
32 Alert Type Response
33 w1 x1 y1
34 w2 x2 y2
. . . .
. . . .
. . . .
. . . .
144 Alert Type Response
145 a1 b1 c1
146 a2 b2 c2
I want to create a new dataframe every time that the row containing "Alert, Type, Response" appears.
I have a hack-y way of getting the outcome - I create vectors containing the start and end row values to determine where each dataframe should start and stop and then use lapply.
list_data <- lapply(1:length(start_rows),
function(x) data[start_rows[x]:end_rows[x],])
This works, however, I am looking for a way to do this without having to determine the row value vectors, as I have 50 other dataframes that also need to be split into 17,000+ smaller dataframes.