R 将calc与堆叠光栅砖一起使用
我试图在R中的两块光栅砖上运行一个线性模型。这两块砖来自不同的来源,但据我所知,它们具有相同的尺寸(lon、lat、time)。我得到了错误:“dimnames(x)中的错误发生后,你能显示R 将calc与堆叠光栅砖一起使用,r,raster,lm,R,Raster,Lm,我试图在R中的两块光栅砖上运行一个线性模型。这两块砖来自不同的来源,但据我所知,它们具有相同的尺寸(lon、lat、time)。我得到了错误:“dimnames(x)中的错误发生后,你能显示s和traceback()的输出吗?只是添加了它们。不知道如何最好地显示,因为它是一个大的光栅堆栈,但我添加了头。请告诉我是否有更好的方法。 #stack two raster bricks s <- stack(rasterbrick1, rasterbrick2) fun=function(x)
s
和traceback()
的输出吗?只是添加了它们。不知道如何最好地显示,因为它是一个大的光栅堆栈,但我添加了头。请告诉我是否有更好的方法。
#stack two raster bricks
s <- stack(rasterbrick1, rasterbrick2)
fun=function(x) { if (is.na(x[1])){ NA } else { lm(x[1:15] ~ x[16:30])$coefficients[2] }}
slope <- calc(s, fun)
index_2002.1 index_2003.1 index_2004.1 index_2005.1 index_2006.1 index_2007.1 index_2008.1
[1,] 0 0 0 0 0 0 0
[2,] 0 0 0 0 0 0 0
[3,] 0 0 0 0 0 0 0
index_2009.1 index_2010.1 index_2011.1 index_2012.1 index_2013.1 index_2014.1 index_2015.1
[1,] 0 0 0 0 0 0 0
[2,] 0 0 0 0 0 0 0
[3,] 0 0 0 0 0 0 0
index_2016.1 index_2002.2 index_2003.2 index_2004.2 index_2005.2 index_2006.2 index_2007.2
[1,] 0 NaN NaN NaN NaN NaN NaN
[2,] 0 NaN NaN NaN NaN NaN NaN
[3,] 0 NaN NaN NaN NaN NaN NaN
index_2008.2 index_2009.2 index_2010.2 index_2011.2 index_2012.2 index_2013.2 index_2014.2
[1,] NaN NaN NaN NaN NaN NaN NaN
[2,] NaN NaN NaN NaN NaN NaN NaN
[3,] NaN NaN NaN NaN NaN NaN NaN
index_2015.2 index_2016.2
[1,] NaN NaN
[2,] NaN NaN
[3,] NaN NaN
traceback()
13: `colnames<-`(`*tmp*`, value = "layer")
12: .local(x, ...)
11: getValues(x)
10: getValues(x)
9: apply(getValues(x), 2, FUN = function(x) {
c(min(x, na.rm = TRUE), max(x, na.rm = TRUE))
})
8: setMinMax(x)
7: setMinMax(x)
6: .local(x, values, ...)
5: setValues(out, x)
4: setValues(out, x)
3: .local(x, fun, ...)
2: calc(s, fun)
1: calc(s, fun)