【发布时间】:2019-09-25 20:38:24
【问题描述】:
我正在使用 match.call 将名为 factanal 的 BASE R 函数重命名为 efa。但我想知道为什么只有在使用参数公式x、efa 时会引发错误:object 'n.obs' not found 但factanal 工作正常?
注意:将data.frame 用于x 时,efa 工作正常。
efa <- function(x, factors, data = NULL, covmat = NULL, n.obs = NA,
subset, na.action, start = NULL, center = FALSE,
scores = c("none", "regression", "Bartlett"),
rotation = "varimax", control = NULL, ...)
{
fit <- factanal(x, factors, data = data, covmat, n.obs = n.obs,
subset, na.action, start = start,
scores = scores,
rotation = rotation, control = control, ...)
fit$call <- match.call(expand.dots = FALSE)
return(fit)
}
# Example of use:
v1 <- c(1,1,1,1,1,1,1,1,1,1,3,3,3,3,3,4,5,6)
v2 <- c(1,2,1,1,1,1,2,1,2,1,3,4,3,3,3,4,6,5)
v3 <- c(3,3,3,3,3,1,1,1,1,1,1,1,1,1,1,5,4,6)
factanal(~v1+v2+v3, factors = 1, data = data.frame(v1, v2, v3)) # Works fine
efa(~v1+v2+v3, factors = 1, data = data.frame(v1, v2, v3)) # Error: object 'n.obs' not found
efa(data.frame(v1, v2, v3), factors = 1) # Works fine
【问题讨论】:
标签: r function dataframe formula