x1 <- c(668, rep(NA, 6), 1852)
x2 <- zoo::na.fill(x1, "extend")
res <- round(x2 - dplyr::lag(x2, default = 0), 0)
I am wondering what is the best way to fill NA values and make sure that the
sum(res) == max(x1, na.rm = T)
x1 <- c(668, rep(NA, 6), 1852)
x2 <- zoo::na.fill(x1, "extend")
res <- round(x2 - dplyr::lag(x2, default = 0), 0)
I am wondering what is the best way to fill NA values and make sure that the
sum(res) == max(x1, na.rm = T)
I'm not sure what you're trying to do, but I noticed that there's a rounding issue.
x1 <- c(668, rep(NA, 6), 1852)
x2 <- zoo::na.fill(x1, "extend")
res <- round(x2 - dplyr::lag(x2, default = 0), 0)
sum(res, na.rm = TRUE)
#> [1] 1851
max(x1, na.rm = TRUE)
#> [1] 1852
sum(res, na.rm = TRUE) == max(x1, na.rm = TRUE)
#> [1] FALSE
Created on 2021-03-07 by the reprex package (v1.0.0)
I am trying to calculate daily cases between cumulative numbers.
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.