'C_cor' not found when using cor() in Apply
As reported by @bertvs, Apply returns an error using 'cor' and 'cov' functions.
mod <- seq(1, 2 * 3)
obs <- seq(1, 2 * 3)
dim(mod) <- c(dataset = 2, member = 3)
dim(obs) <- c(dataset = 2, member = 3)
outp <- Apply(data = list(x = obs, x = mod),
target_dims = list(x = c("member"), y = c("member")),
fun = cor)
Error in (function (x, y = NULL, use = "everything", method = c("pearson", : object 'C_cor' not found
To avoid it there are two options:
1.- Declare the function before using it
C_cor <- stats:::C_cor
outp <- Apply(data = list(x = obs, x = mod),
target_dims = list(x = c("member"), y = c("member")),
fun = cor)
2.- Define a function using cor:
outp <- Apply(data = list(x = obs, y = mod),
target_dims = list(x = c("member"), y = c("member")),
fun = function(x, y){cor(x, y)})
This last case is the one we can use in apply:
apply(mod, 1, function(x){cor(x, c(1,2,3))})
For now, I don't know any fix I can do in Apply code since I think this is a problem from cor function.
Suggestions and ideas are more than welcome.
Cheers,
Núria