R-生成伪积分数据时如何包含时间方面

  • 本文关键字:何包含 时间 方面 数据 r dismo
  • 更新时间 :
  • 英文 :


我对卫星标记的海龟有608个观察结果。我想通过包括海面温度,电流速度,风速。当然,标记和环境数据在空间和时间上都有变化的环境数据。我使用以下代码从此处改编的代码生成了伪积分数据。但是,我现在已经想到我生成的数据点只是空间样本。是否有某种方式可以编辑此代码以便在时间上进行示例,以便我所产生的CSV具有每个点的日期/时间,以便我可以将其与我的环境数据匹配?另外,我可以尝试的其他包裹可以让我这样做吗?

dir.create(path = "data")
library("sp")
library("raster")
library("maptools")
library("rgdal")
library("dismo")
bioclim.data <- getData(name = "worldclim",
                        var = "bio",
                        res = 2.5,
                        path = "data/")
# Read in observations
obs.data <- read.csv(file = "data/Presence.csv")

# Determine geographic extent of data
max.lat <- ceiling(max(obs.data$Latitude))
min.lat <- floor(min(obs.data$Latitude))
max.lon <- ceiling(max(obs.data$Longitude))
min.lon <- floor(min(obs.data$Longitude))
geographic.extent <- extent(x = c(min.lon, max.lon, min.lat, max.lat))

# Use the bioclim data files for sampling resolution
bil.files <- list.files(path = "data/wc2-5", 
                        pattern = "*.bil$", 
                        full.names = TRUE)
# only need one file, so use the first one in the list of .bil files
mask <- raster(bil.files[1])
# Randomly sample points (same number as our observed points)
background <- randomPoints(mask = mask,     # Provides resolution of sampling points
                           n = nrow(obs.data),      # Number of random points
                           ext = geographic.extent, # Spatially restricts sampling
                           extf = 1.25)             # Expands sampling a little bit

write.csv(background, "pseudo-absence.csv")

i仅通过以下代码生成随机时间并合并结果及以上。

来解决此问题。
#ADD TIMES 
time.start <- as.POSIXct('2014-12-01T01:00:00z', format = "%Y-%m-%dT%H:%M:%S")
time.end <- as.POSIXct('2015-04-30T01:00:00z', format = "%Y-%m-%dT%H:%M:%S")
seconds <- difftime(time.end, time.start, units = "secs")
# Option with runif()
v <- round(runif(6000, 0, seconds))
# Option with sample()
v <- sample(1:seconds, 6000, replace = T)
time.uniform <- time.start + v   
write.csv(time.uniform, "time.csv")
tag<-read.csv("pseudo-absence.csv")
time<- read.csv("time.csv")
myfulldata = merge(tag,time)
write.csv(myfulldata, "pseudo-absence_with_time.csv")

最新更新