'X' must be numeric error in Decorana/VEGAN function after subsetting in R 中

'X' must be numeric error in Decorana/VEGAN function after subsetting in R

我一直在 rowSums(veg) 中得到这个 error:Error :

 'x' must be numeric

我从一个大数据集中提取了一小部分子集,当我 运行 DCA 排序时,我不断收到上述错误消息。我检查了,但我没有显示行中的字符数据。

install.packages("vegan")
library(vegan)

Dataveg2018A <- subset(DatasetMerg, Year == "2018" & Block == "A",
                                     select = 4:7)
ord1<-decorana(Dataveg2018A)

有人可以告诉我我做错了什么吗?

子集 (DatasetMerg) 的示例数据

        structure(list(Year = structure(c(3L, 3L, 3L, 3L, 3L, 3L, 3L, 
    3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L), .Names = c("18A01", 
    "18A02", "18A03", "18A04", "18A05", "18A06", "18A07", "18A08", 
    "18A09", "18A10", "18A11", "18A12", "18A13", "18A14", "18A15", 
    "18A16", "18A17", "18A18", "18A19", "18A20"), .Label = c("2001", 
    "2008", "2018"), class = "factor"), Block = structure(c(1L, 1L, 
    1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 
    1L, 1L), .Names = c("18A01", "18A02", "18A03", "18A04", "18A05", 
    "18A06", "18A07", "18A08", "18A09", "18A10", "18A11", "18A12", 
    "18A13", "18A14", "18A15", "18A16", "18A17", "18A18", "18A19", 
    "18A20"), .Label = c("A", "B", "C", "D", "E", "F", "G", "H", 
    "I", "J", "X"), class = "factor"), Plot = structure(1:20, .Names = c("18A01", 
    "18A02", "18A03", "18A04", "18A05", "18A06", "18A07", "18A08", 
    "18A09", "18A10", "18A11", "18A12", "18A13", "18A14", "18A15", 
    "18A16", "18A17", "18A18", "18A19", "18A20"), .Label = c(" 1", 
    " 2", " 3", " 4", " 5", " 6", " 7", " 8", " 9", "10", "11", "12", 
    "13", "14", "15", "16", "17", "18", "19", "20", "21", "22", "23", 
    "24", "25", "26", "27", "28", "29", "30", "31", "32", "33", "34", 
    "35", "36", "37", "38", "39", "40", "41", "42", "43", "44", "45", 
    "46"), class = "factor"), Agrimonia.eupatoria = structure(c(3L, 
    2L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 
    1L, 1L, 1L), .Names = c("18A01", "18A02", "18A03", "18A04", "18A05", 
    "18A06", "18A07", "18A08", "18A09", "18A10", "18A11", "18A12", 
    "18A13", "18A14", "18A15", "18A16", "18A17", "18A18", "18A19", 
    "18A20"), .Label = c("0", "1", "2", "6"), class = "factor"), 
        Agrostis.capillaris = structure(c(1L, 1L, 1L, 1L, 1L, 1L, 
        1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L), .Names = c("18A01", 
        "18A02", "18A03", "18A04", "18A05", "18A06", "18A07", "18A08", 
        "18A09", "18A10", "18A11", "18A12", "18A13", "18A14", "18A15", 
        "18A16", "18A17", "18A18", "18A19", "18A20"), .Label = c("0", 
        "2", "3", "4", "6"), class = "factor"), Agrostis.gigantea = structure(c(1L, 
        1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 2L, 3L, 2L, 1L, 3L, 3L, 
        4L, 3L, 1L, 1L), .Names = c("18A01", "18A02", "18A03", "18A04", 
        "18A05", "18A06", "18A07", "18A08", "18A09", "18A10", "18A11", 
        "18A12", "18A13", "18A14", "18A15", "18A16", "18A17", "18A18", 
        "18A19", "18A20"), .Label = c("0", "2", "3", "4", "6"), class = "factor"), 
        Agrostis.stolonifera = structure(c(5L, 1L, 1L, 1L, 1L, 1L, 
        1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L), .Names = c("18A01", 
        "18A02", "18A03", "18A04", "18A05", "18A06", "18A07", "18A08", 
        "18A09", "18A10", "18A11", "18A12", "18A13", "18A14", "18A15", 
        "18A16", "18A17", "18A18", "18A19", "18A20"), .Label = c("0", 
        "1", "18", "2", "3", "38", "4", "6", "68", "8"), class = "factor")), 
  .Names = c("Year", 
    "Block", "Plot", "Agrimonia.eupatoria", "Agrostis.capillaris", 
    "Agrostis.gigantea", "Agrostis.stolonifera"), row.names = c("18A01", 
    "18A02", "18A03", "18A04", "18A05", "18A06", "18A07", "18A08", 
    "18A09", "18A10", "18A11", "18A12", "18A13", "18A14", "18A15", 
    "18A16", "18A17", "18A18", "18A19", "18A20"), class = "data.frame")

所有 你的变量都是非数字(因子),在原始 DatasetMerg 及其子集(Dataveg2018A)中。您可以看到这个发出命令 str(DatasetMerg) ,它将所有变量作为因子(及其子集相同)。您还可以在自己的完整显示 DatasetMerg 中看到这一点,其中所有物种数据都作为因子给出。这只是您的第一个物种,您为其提供的数据为:

    Agrostis.capillaris = structure(c(1L, 1L, 1L, 1L, 1L, 1L, 
    1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L), .Names = c("18A01", 
    "18A02", "18A03", "18A04", "18A05", "18A06", "18A07", "18A08", 
    "18A09", "18A10", "18A11", "18A12", "18A13", "18A14", "18A15", 
    "18A16", "18A17", "18A18", "18A19", "18A20"), .Label = c("0", 
    "2", "3", "4", "6"), class = "factor")

请注意最后的定义 class = "factor"。这些值(所有 1L)给出了您的因子水平的索引,这些水平在 .Label 中给出。所以你所有的数据都是一个(1L)并且这些显示为 .Labels[1L] == c("0", "2", "3", "4", "6")[1L] == "0" 这是非数字(一个字符)。