【问题标题】:Presence-absence matrix存在-不存在矩阵
【发布时间】:2022-01-20 13:29:30
【问题描述】:

我正在尝试根据letsR 包和lets.presab.points() 函数中的示例代码生成存在-不存在矩阵网格。

示例代码:

species <- c(rep("sp1", 100), rep("sp2", 100),
             rep("sp3", 100), rep("sp4", 100))
x <- runif(400, min = -69, max = -51)
y <- runif(400, min = -23, max = -4)
xy <- cbind(x, y)
PAM <- lets.presab.points(xy, species, xmn = -93, xmx = -29, 
                          ymn = -57, ymx = 15)
summary(PAM)

我的代码:

records <- read.csv("directoryremovedforprivacy.csv")
x <- records$lon
y <- records$lat
xy <- cbind(x, y)
PAM2 <- lets.presab.points(xy, records, xmn = -11.5, xmx = 3,
                          ymn = 49, ymx = 61)
summary(PAM2)

但是我得到以下错误:

Error in xy[pos, , drop = FALSE] : (subscript) logical subscript too long
In addition: Warning message:
In xtfrm.data.frame(x) : cannot xtfrm data frames
> summary(PAM2)
Error in h(simpleError(msg, call)) : 
  error in evaluating the argument 'object' in selecting a method for function 'summary': object 'PAM2' not found

【问题讨论】:

    标签: r matrix


    【解决方案1】:

    根据错误信息,问题可能出在lets.presab.points 中的records。它需要一个物种列表,但你正试图给它一个数据框。因此,在您的示例代码中,species 是一个字符向量,因此您的代码也需要采用相同的格式。所以,你可能需要做这样的事情(虽然我不确定你的records 数据的格式是什么):

    library(letsR)
    
    PAM2 <- lets.presab.points(xy, records$species, xmn = -11.5, xmx = 3,
                              ymn = 49, ymx = 61)
    

    species 需要与xy 长度相同。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2023-01-20
      • 2020-08-01
      • 2015-04-20
      • 2014-05-17
      • 2017-10-12
      相关资源
      最近更新 更多