I have a data frame where I want to split by a group based on a single group and would like to split it so I can encapsulate everything from Valley 1 to Valley 2, Valley 2 to Valley 3 and so on.
Time Peaks ID
1 0.00 Data 1
2 0.36 Data 2
3 0.75 Valley 1
4 1.14 Peak 1
5 1.54 Data 3
6 1.93 Data 4
7 2.32 Valley 2
8 2.72 Peak 2
9 3.12 Valley 3
Desired output:
df1
3 0.75 Valley 1
4 1.14 Peak 1
5 1.54 Data 3
6 1.93 Data 4
7 2.32 Valley 2
df2
7 2.32 Valley 2
8 2.72 Peak 2
9 3.12 Valley 3
Data in format for direct use in R:
dat <- structure(list(Row = c(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12,
13, 14, 15, 16), Time = c(0, 0.36, 0.75, 1.14, 1.54, 1.93, 2.32,
2.72, 3.12, 3.51, 3.9, 4.3, 4.69, 5.08, 5.47, 5.87), Value = c(455,
456, 456, 459, 456, 456, 455, 458, 455, 458, 455, 456, 461, 458,
458, 459), Peaks = c("Data", "Data", "Valley", "Peak", "Data",
"Data", "Valley", "Peak", "Valley", "Peak", "Valley", "Data",
"Peak", "Data", "Valley", "Data"), Peak_id = c(1, 2, 1, 1, 3,
4, 2, 2, 3, 3, 4, 5, 4, 6, 5, 7)), row.names = c(NA, -16L), class = c("tbl_df",
"tbl", "data.frame"))