0

I would like to use the rollapply function from the zoo package in R to calculate a moving IQR, but this fails when missing data (NA's) are reached in my data series.

data_series <- c(4,7,4,7,3,6,5,8,5,NA,9,0,5,8,1,3,6,5)
roll_iqr <- rollapply(data_series, width = 5, fill = NA, FUN = IQR)

Error in quantile.default(as.numeric(x), c(0.25, 0.75), na.rm = na.rm,  : 
missing values and NaN's not allowed if 'na.rm' is FALSE

Is there a way to tell the rollapply function to include the na.rm = T argument that would normally be part of the IQR function?

user8229029
  • 883
  • 9
  • 21
  • 3
    Just add it to your function call. `rollapply(data_series, width = 5, fill = NA, FUN = IQR, na.rm=TRUE)`. The documentation indicates that any extra parameters `...` are also passed along to your function. – MrFlick Dec 09 '22 at 21:23

0 Answers0