我有一个在不同日子收集的空间多边形数据框列表。我希望为列表中的每一天添加时间,这样我就可以为“Z”(DDD.LFRP)变量设置子集并具有基于时间/日期的方法。 下面是空间的多边形列表的一个子集:将时间变量添加到R中的空间多边形数据框列表中
[[1]]
class : SpatialPolygonsDataFrame
features : 128
extent : -127.44, -67.8964, 1.000039, 31.71804 (xmin, xmax, ymin, ymax)
coord. ref. : +proj=longlat +datum=WGS84 +ellps=WGS84 +towgs84=0,0,0
variables : 1
names : DDD.LFRP
min values : 16.6
max values : 488.5
[[2]]
class : SpatialPolygonsDataFrame
features : 126
extent : -129.04, -67.8964, 3.759985, 31.71804 (xmin, xmax, ymin, ymax)
coord. ref. : +proj=longlat +datum=WGS84 +ellps=WGS84 +towgs84=0,0,0
variables : 1
names : DDD.LFRP
min values : 14
max values : 335.2
如何添加添加时间/日期这个好吗? 从一组字符串创建时间戳从文件名子集:
##Define date string
regexp2<-"_([[:digit:]]{12})"
DatesDL3<-sapply(names(DL3), function(x)stri_extract_first_regex(x,regexp2))
DatesL<-gsub("_", "", DatesDL3)
DDO2<-data.frame(DatesL)
DDO3<-DDO2[["DatesL"]]
#COnvert straight to dates
Timex<-strptime(DDO3, "%Y%m%d%H%M")
Timex
[1] "2008-12-01 04:00:00 GMT" "2008-12-01 06:30:00 GMT"
然后我试图通过@RobertH
polsdatetime <- lapply(1:length(DL3), function(i) {
p <- DL3[[i]]
p$datetime <- Timex[i]
p
})
polsdatetime
[[1]]
class : SpatialPolygonsDataFrame
features : 119
extent : -124.23, -68.26758, 2.141337, 31.80002 (xmin, xmax, ymin, ymax)
coord. ref. : +proj=longlat +datum=WGS84 +ellps=WGS84 +towgs84=0,0,0
variables : 2
Error in as.matrix.data.frame(X) :
dims [product 119] do not match the length of object [130]
你想给每个'SpatialPolygonsDataF添加一个'timestamp'变量rame'在列表中? – tospig
@topsig,是;用于列表中的每个图层但不包含空间多边形数据框图层中的单个多边形。即上面的两层对每一层都有一个日期/时间。 –
你可以用你试过的代码更新你的问题,并且输出结果是什么? – tospig