How can I sum columns values till a selected value?I want sum of new_cases of all Afghanistan instances
Please see the reprex FAQ for information on how to attract more and better answers.
values <- c(21, 63, 39, 57, 34, 33, 52, 26, 22, 46, 92, 16,
56, 31, 81, 70, 14, 36, 59, 1, 55, 92, 15, 86, 2)
# cumulative sums
running <- cumsum(values)
# predetermined target
cutoff <- 300
# last value less than target
tail(running[which(running < cutoff)],1)
#> [1] 299
# its position
length(running[which(running < cutoff)])
#> [1] 7
# sequence of the values below the cutoff
values[which(running < cutoff)]
#> [1] 21 63 39 57 34 33 52
Created on 2021-01-04 by the reprex package (v0.3.0.9001)
This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.
If you have a query related to it or one of the replies, start a new topic and refer back with a link.