Skip to content

quantile function with Apply

Hi,

I wanted to make my code more flexible by defining a quantile function that depends on a variable and then using it within multiApply. However, I encounter an error stating that the object “variable” cannot be found. I’ve tried forcing the variable and a few other workarounds, but nothing has worked so far. Is there a way to solve this issue?

Below is a simple example to illustrate the problem:

> p <- 0.9
> fun <- function(x, p){quantile(x, p)}
> Apply(array(1:10, c(t=10)), target_dims = 't', fun = fun)
Error in (function (x, p)  : argument "p" is missing, with no default

Thanks ! Alberto