我试图在R中生成缺席和存在数据集以用于后续模型。我有多个带有位置的csv表和与这些位置匹配的植被栅格。我需要生成一个存在缺失数据集来模拟栖息地选择。我已经完成了脚本:
setwd("~/Masters/Research Project/GIS/GIS_Focal_Raster")
library(raster)
## import the raster layer used as the mask ##
absent<-raster("Veg_B2.tif")
mask<-raster(absent)
present<-read.csv("B2_Lon_Lat.csv")
present
## select 500 random points ##
## set seed to assure that the examples will always have the same ##
## random sample. ##
library(dismo)
set.seed(1963)
bg<-randomPoints(mask,500)
## set up the plotting area for two maps ##
par(mfrow=c(1,2))
plot(!is.na(mask),legend=FALSE,main="random")
points(bg,cex=0.5)
## repeat the sampling, but limit the area of sampling using a spatial ##
## extent ##
library(raster)
library(extent)
r<-raster("Veg_B2.tif")
e<-extent(r)
bg2<-randomPoints(mask,50,ext=e)
plot(!is.na(mask),legend=FALSE)
plot(e,add=TRUE,col='red')
points(bg2,cex=0.5)
## pseudo-absence points ##
library(rgdal)
present<-read.csv("B2_Lon_Lat.csv")
coordinates(present)=~lon+lat
然后我想出了错误
坐标(本)=〜经度纬度+ eval中的错误(predvars,data,env):object&#39; lon&#39;未找到 有什么建议怎么继续?