我有一个循环,我正在下采样栅格,然后找到那些栅格的标准偏差。我的代码是
i=0
while(i<10)
{
# Get the Raster + Noise raster
NewRaster=NoisyRaster(OriginalRaster,NoiseMatrix)
DownSampledRaster=DownSampleRaster(NewRaster,CellSize,MEAN)
TheMatrix=as.matrix(DownSampledRaster)
StandardDev=sd(TheMatrix, na.rm=T)
print(StandardDev)
i=i+1
}
问题是,当它打印标准偏差时,它看起来像这样:
[1] number
[2] number etc.
我需要进行100多次迭代,我需要能够找到这些数字的均值和标准差。如何将这些数字放入向量中,以便我可以轻松完成?
答案 0 :(得分:0)
我尝试重写代码,这就是我提出的:
StandardDev = vector(mode = "numeric")
for(i in 1:10) {
# Get the Raster + Noise raster
NewRaster=NoisyRaster(OriginalRaster,NoiseMatrix)
DownSampledRaster=DownSampleRaster(NewRaster,CellSize,MEAN)
TheMatrix=as.matrix(DownSampledRaster)
StandardDev[i] = sd(TheMatrix, na.rm=T)
}