Quick question: Would anyone help explain why I got all NA's for the rolling median output. I set na.rm to TRUE but that doesn't seem to help. Thanks!
library(RcppRoll)
input <- c(1:10, rep(NA, 190))
output <- roll_median(input, n = 120, fill = NA, align = 'right', na.rm = TRUE)
For reference, I expect the right output to be:
my.expectation <- rep(NA, 119)
for(i in 1:81){
my.expectation <- c(my.expectation, median(input[i:(i + 119)], na.rm = TRUE))
}
I know how to do this with rollapply:
library(zoo)
median.n <- function(x){median(x, na.rm = TRUE)}
rollapplyr(data = input, width = 120, FUN = median.n, fill = NA)
But for speed reason (I am manipulating a data frame with tens of millions of rows), I wish to do it with roll_median. Does anyone know how to accomplish this? Thanks!