要实现的正确用地是什么。

问题描述 投票:0回答:1
r Terra软件包似乎没有一个在Terra栅格上起作用的ins.numeric()函数?

I表示下面的hacky替代方案非常慢。有人可以提供更优雅的解决方案吗?

#set up data x1 = x2 = x3 = x4 = rast( nrows=180, ncols=360, nlyrs=1, xmin=-180, xmax=180, ymin=-90, ymax=90) x1[] = 1.0 x2[] = F x3[] = "cat" x4[] = as.integer(1) #create multiband raster r4 = c(x1,x2,x3,x4) #test for numeric - the second hacky approach works SLOWLY, but hacky # Are the contents of my raster spooling out into memory? sapply(r4, is.numeric) sapply(r4, function(x)is.numeric(x[])) #test for bool - terra function works sapply(r4, is.bool) #test for factor - works sapply(r4, is.factor) #test for integer - second approach (terra function) works sapply(r4, is.integer) sapply(r4, is.int)

	
您可以做
r terra
1个回答
0
投票
sapply(r4[1], is.numeric) #lyr.1 lyr.1 lyr.1 lyr.1 # TRUE FALSE FALSE TRUE


最新问题
© www.soinside.com 2019 - 2025. All rights reserved.