如何使用“样本函数”提取空间点的随机样本并在 R 中使用“for 循环”重复该过程

问题描述 投票:0回答:0

我在 Mac OS 的 RStudio 中工作,我正在为代码而苦苦挣扎。 我有一个由 128 个点和三个列(ID、Easat、North)组成的 SpatialPointsDataFrame。我想从这些站点中抽取 10% 的随机样本(即 n = 115)。此外,我想重复此过程 10 次,即创建 10 次随机样本提取迭代。我的目标是获得 10 个独立的组,其中包含从原始 128 个点中提取的 115 个随机点。

我尝试了几个密码都不成功,包括

for loops
function
lapply
。但是我要么没有得到我正在寻找的东西,要么得到不同类型的错误。 让我更接近的最简单的代码是:

nsites <- sites # defining my database
nsim <- 10 # setting the number of simulations
nsamp <- 115 # defining the number of points I want to extract
s90 <- nsites[sample(nrow(nsites), size = nsamp, replace = FALSE, prob = NULL), ]
for(i in 1:nsim) {
        s90r[nsim] <- list(s90) # create a list to store the results
        print(s90r)
}

这导致了 10 组点,但是当我绘制每组时,我意识到它们是相同的 115 点,而不是 10 组不同的随机 115 点。

非常感谢您的任何建议!

最好的,

爱德华多

for-loop random geospatial spatial sample
© www.soinside.com 2019 - 2024. All rights reserved.