ncol(xj) 中的错误:使用 rowSums 找不到对象“xj" [英] Error in ncol(xj) : object 'xj' not found using rowSums
问题描述
我正在为数据框使用 R 和 rowSums 函数,如本文所述:在spatialGridDataFrame上求和:rowSums或colSums.现在起诉 rowSums 如下:
I'm using R and rowSums function for a data frame as discussed in this post: Sum over spatialGridDataFrame: rowSums or colSums. Now suing rowSums as follows:
FLintMod[[2+nsim]] <- rowSums(FLintMod@data[, 2:(1+nsim)], na.rm=TRUE)
现在我面临新的错误,我真的不知道为什么我会收到这个错误:
Now I'm facing new error and I really don't have any idea why I'm getting this error:
Error in ncol(xj) : object 'xj' not found
你能帮我理解这个问题并解决它吗.
Could you please help me understand this problem and solve it.
供您参考,此代码之前有效,但在改进代码并专门执行以下工作以将栅格返回到空间网格数据框之后,我收到此错误:
For your information, this code worked before but after improving code and specially doing the following work to return raster to spatial grid data frame I got this error:
FLintRaster <- raster(FLint[i+1])
FLintRasterMod <- mask(FLintRaster, FloodExtent)
FLintMod[[i+1]] <- as(FLintRasterMod,"SpatialGridDataFrame")@data
最好,
推荐答案
我终于找到了答案.我生成了数据框@数据框!为了将栅格返回到数据框,我应该使用 as.vector() 函数.
I finally found my answer. I generated data frame @ data frame! In oredr to return raster to data frame I should use as.vector() function.
FLintRaster <- raster(FLint[i+1])
FLintRasterMod <- mask(FLintRaster, FloodExtent)
FLintMod[[i+1]] <- as.vector(FLintRasterMod, mode='any')
如果有人能从技术角度解释我的情况,我会很高兴.我对 R 很陌生,并渴望学习它的基础知识.
I'll be happy if someone can explain more technically what happened in my case. I'm very new to R and eager to learn the basics of that.
最好,
这篇关于ncol(xj) 中的错误:使用 rowSums 找不到对象“xj"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!