我尝试生成零和一的数组,转换为光栅并绘制它。 我希望有随机模式,那么为什么在这个光栅中有明显的模式? 我在脚本中做错了吗?
# creating vector containing "0" and "1" values...
x<-sample(c(0,1), 1000, replace=TRUE)
# ...converting it into array...
x_arr<-array(x, dim=c(100,100))
# ....nest into raster
x_rast<-raster(x_arr)
# ...and making plot
plot(x_rast)
最佳答案
因为100*100给出的是10000,不是1000,R会重复填满。尝试
library(raster)
x<-sample(c(0,1), 10000, replace=TRUE)
这个例子很好,但请不要忘记在发布前将它粘贴到原始 R 中。你忘记了图书馆。
关于r - 为什么随机值会产生模式?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20243765/