R中的标准cov()函数在DSX中不起作用

问题描述:

R cov()中的标准协方差函数在DSX中不起作用。R中的标准cov()函数在DSX中不起作用

我跑了states.x77数据集下面的代码:

cov(states) 

,我得到了以下错误消息:

Error in (function (classes, fdef, mtable) : unable to find an 
    inherited method for function ‘cov’ for signature ‘"matrix"’ 
    Traceback: 
    1. cov(states) 
    2. (function (classes, fdef, mtable) 
    . { 
    . methods <- .findInheritedMethods(classes, fdef, mtable) 
    . if (length(methods) == 1L) 
    . return(methods[[1L]]) 
    . else if (length(methods) == 0L) { 
    . cnames <- paste0("\"", vapply(classes, as.character, 
    . ""), "\"", collapse = ", ") 
    . stop(gettextf("unable to find an inherited method for function %s 
    for signature %s", 
    . sQuote([email protected]), sQuote(cnames)), domain = NA) 
    . } 
    . else stop("Internal error in finding inherited methods; didn't 
    return a unique method", 
    . domain = NA) 
    . })(list("matrix"), structure(function (x, ...) 
    . { 
    . standardGeneric("cov") 
    . }, generic = structure("cov", package = "SparkR"), package = 
    "SparkR", group = list(), valueClass = character(0), signature = 
    "x", default = `\001NULL\001`, skeleton = (function (x, 
    . ...) 
    . stop("invalid call in method dispatch to 'cov' (no default 
    method)", 
    . domain = NA))(x, ...), class = 
    structure("nonstandardGenericFunction", package = "methods")), 
    . <environment>) 
    3. stop(gettextf("unable to find an inherited method for function 
    %s for signature %s", 
    . sQuote([email protected]), sQuote(cnames)), domain = NA) 

我不知道我在做什么错。事实证明,stats :: cov()被SparkR :: cov()覆盖。一旦我将我的代码替换为:

stats::cov() 

函数返回了所需的结果。

谢谢, Venky

+0

您是如何得到此错误的? – lebelinoz

+0

我在states.x77数据集上运行了cov(states)。 stats :: cov(states)解决了这个问题。谢谢。 – Venky

中的R cov()来自stats包。在R中,导入库的顺序非常重要,它们经常会覆盖其他功能。看起来就是这样。您可以通过指定软件包名称来调用其他软件包的覆盖函数,如下所示:

stats::cov(<dataset>) 
+0

谢谢Sumit! stats :: cov()的作品。 – Venky

+0

完美。我发现'stats :: cov'被'SparkR :: cov'覆盖。 https://spark.apache.org/docs/latest/api/R/index.html –