Home > Mobile >  Presence-absence matrix
Presence-absence matrix

Time:12-18

I'm trying to generate a presence-absence matrix grid based on the example code from the letsR package and lets.presab.points() function.

Example code:

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)

My code:

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)

However I get the following error:

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

CodePudding user response:

According to the error message, the issue is probably with records in lets.presab.points. It expects a list of species, but you are trying to give it a dataframe. So, in your example code, species is a character vector, so it needs to be the same format for your code too. So, you might need to do something like this (although I'm uncertain what the format of your records data is):

library(letsR)

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

species needs to be the same length as xy.

  • Related