Is it possible to use cumsum()
iteratively in one column with start - stop conditional on other column:
- given the dataframe
df
with one columnX
where values are ascending. cumsum()
should stop when reaching 10 or a multiple of ten (e.g.20,30,40,...).- then after reaching this point (10,20,30,40,..) cumsum() should start new... and so on.
- In case of ties (20,20 or 30,30)
cumsum
should stop in the last occurrence of 10, 20, 30, 40,... this is the dataframe:
df <- structure(list(X = c(55L, 95L, 39L, 52L, 22L, 93L, 76L, 82L,
77L, 58L, 60L, 19L, 31L, 43L, 65L, 56L, 18L, 66L, 21L, 49L, 13L,
37L, 36L, 51L, 41L, 7L, 91L, 3L, 11L, 65L, 51L, 32L, 25L, 10L,
5L, 7L, 8L, 3L, 72L, 66L, 93L, 24L, 48L, 44L, 91L, 60L, 62L,
89L, 100L, 69L, 5L, 89L, 54L, 19L, 39L, 93L, 60L, 64L, 89L, 81L,
24L, 9L, 51L, 9L, 7L, 69L, 19L, 51L, 39L, 100L, 83L, 67L, 33L,
84L, 66L, 25L, 20L, 87L, 55L, 56L, 83L, 52L, 96L, 42L, 16L, 64L,
45L, 30L, 55L, 29L, 16L, 73L, 40L, 29L, 92L, 6L, 38L, 12L, 38L,
89L)), class = "data.frame", row.names = c(NA, -100L))
Many thanks!!!
desired output as an example up to 30.