合并多个lapply

时间:2018-09-03 20:40:04

标签: r nested apply lapply

我有三个套用例程,我想合并为一个。我遇到了麻烦,我的三个lapply是 tmp2,coord,mtx_ll ,代码如下:

#libraries
library(spData)
library(sf)
library(sp)
#input
zones = nz
zones <- as(zones, "Spatial")
nodes = nz_height
nodes <- as(nodes, "Spatial")
#parameter
s = 1:nrow(zones)
#SpatialQuery
tmp2  <- lapply(s, function(x) {
  nodes[zones[x, ], ]
})
#coordinates extraction
coord <- lapply(X = tmp2, FUN = function(x) coordinates(x))
#distance matrix
mtx_ll <- lapply(s, function(i){
  apply(X = coord[[i]], MARGIN = 1, 
        FUN = function(x) spDistsN1(coord[[i]], x, longlat = T))
})

有什么想法吗?

0 个答案:

没有答案