使用大光栅(R)查找表格

使用大光栅(R)查找表格,r,function,spatial,r-raster,bigdata,R,Function,Spatial,R Raster,Bigdata,真的希望你能帮我。提前感谢您,感谢我从这些页面学到的一切。抱歉,我的专业技能受到兼职性质的限制,我正试图学习R 我的目标是: 使用(大)光栅查找表格反转 我现在所拥有的: #Observed data (in this case just as a dataframe) obs <- data.frame(runif(100,0,1)) #Two sets of simulated data (often n >10 000) sim.A <- data.frame(runi

真的希望你能帮我。提前感谢您,感谢我从这些页面学到的一切。抱歉,我的专业技能受到兼职性质的限制,我正试图学习R

我的目标是: 使用(大)光栅查找表格反转

我现在所拥有的:

#Observed data (in this case just as a dataframe)
obs <- data.frame(runif(100,0,1))

#Two sets of simulated data (often n >10 000)
sim.A <- data.frame(runif(1000,0,1))

sim.B <- data.frame(runif(1000,0,1))

#Calculate the error [cost] for each observed value and every simulated(A) value
error.fun <- function(x){sqrt((x-sim.A)^2)}              
error <- apply(obs,1,error.fun) 

#Find the position of the min [error] value
min.func <- function(x){which(x == min(x),arr.ind = F)}    
cost.min <- apply(error,2,min.func)

#Subset the simulated (B) dataset at the position of the least error[cost.min]
LUT.values = data.frame(sim.B[cost.min,])
#观察到的数据(在本例中仅作为数据帧)
obs(10000)

模拟A您缺少的是观察到的
模拟的
的平均值:

rmse <- sqrt(mean((obs-sim)^2)) 

rmse我想这就是你想要的

library(raster)
r <- raster(ext=extent(0, 100, 0, 100), res=1, crs="+proj=utm +zone=36 +south +datum=WGS84 +units=m")

set.seed(0)
values(r) <- runif(ncell(r), 0, 1)

sim.A <- runif(1000,0,1)
sim.B <- runif(1000,0,1)

cost <- function(x) {
  y <- abs(x-sim.A)
  sim.B[which.min(y)]
}
x <- calc(r, cost)
库(光栅)

r谢谢你,罗伯特。这是完美的,而且要快得多。我的低精度仍然存在,但我会继续深入研究(病态问题等)。不过,谢谢你的解决方案。
library(raster)
r <- raster(ext=extent(0, 100, 0, 100), res=1, crs="+proj=utm +zone=36 +south +datum=WGS84 +units=m")

set.seed(0)
values(r) <- runif(ncell(r), 0, 1)

sim.A <- runif(1000,0,1)
sim.B <- runif(1000,0,1)

cost <- function(x) {
  y <- abs(x-sim.A)
  sim.B[which.min(y)]
}
x <- calc(r, cost)