【问题标题】:RDA, Error in colMeans(x, na.rm = TRUE) : 'x' must be numeric, when data is numeric?RDA,colMeans(x,na.rm = TRUE)中的错误:'x'必须是数字,当数据是数字时?
【发布时间】:2023-03-28 03:39:01
【问题描述】:

我想在 R 中使用 vegan 执行 rda。

我的代码如下所示:

species<- read.delim("springspecies1.txt", header=T)
envdata<- read.delim("springenv1.txt", header=T)

RDA <- rda(species~Temperature + Salinity + O2 + Phosphate + Nitrate + Silica, envdata, scale=T, na.action=na.omit)

我收到错误消息:

Error in colMeans(x, na.rm = TRUE) : 'x' must be numeric

当我检查我的数据时,我得到:

sapply(species, mode)
      Station          Year         Month     S.marinoi      C.tripos 
    "numeric"     "numeric"     "numeric"     "numeric"     "numeric" 
      P.alata     P.seriata    R.setigera    C.pelagica D.confervacea 
    "numeric"     "numeric"     "numeric"     "numeric"     "numeric" 
  C.decipiens    P.farcimen       C.furca 
    "numeric"     "numeric"     "numeric"

我的数据集中没有 NA 或空白。但似乎物种数据集是问题所在。我用该物种编译了一个新的数据集,但我又遇到了同样的问题。有什么想法吗?

【问题讨论】:

  • 你可能有因素。使用sapply(species, class),而不是mode,因为mode 仍会为numeric 提供factors

标签: r vegan rda


【解决方案1】:

您应该使用“类”进行测试,而不是使用“模式”。您可能有一个因子列。它们是数字模式,但使用 'is.numeric' 测试 FALSE。

【讨论】:

  • Userul 的答案应该被赞成。 “最正确”的答案会被选中。 (请阅读常见问题解答。)
猜你喜欢
  • 2020-12-19
  • 2019-10-04
  • 2018-01-27
  • 2018-05-23
  • 2017-10-25
  • 2020-06-18
  • 2018-01-17
  • 2021-02-14
  • 1970-01-01
相关资源
最近更新 更多