我使用raster :: subs函数使用主键用data.table(和data.frame)中的值替换栅格中的值,但是我得到了错误:
Error in .local(x, y, ...) : 'by' is not a valid column name
有时候;
Error in .local(x, y, ...) : duplicate "by" values not allowed
示例:
require(raster)
require(data.table)
r <- raster(xmn=0,xmx=1000,ymn=0,ymx=1000,res=c(1,1))
r[] <- 1:ncell(r)
dt <- data.table(class = sample(c("red","blue","yellow","green"),1000000,rep=T),ID=1:1000000,random=sample(60:394,1000000,rep=T),value=runif(1,min=0,max=1))
df <- data.frame(class = sample(c("red","blue","yellow","green"),1000000,rep=T),ID=1:1000000,random=sample(60:394,1000000,rep=T),value=runif(1,min=0,max=1))
r.sub <- raster::subs(r, dt, by="ID", which="value", subsWithNA = TRUE)
Error in .local(x, y, ...) : duplicate "by" values not allowed
r.sub <- raster::subs(r, df, by="ID", which="value", subsWithNA = TRUE)
Error in .local(x, y, ...) : duplicate "by" values not allowed
以下工作:
dt <- setcolorder(dt,c(2,4,1,3))
r.sub <- raster::subs(r, dt, by="ID", which="value", subsWithNA = TRUE)
df <- df[,c(2,4,1,3)]
r.sub <- raster::subs(r, df, by="ID", which="value", subsWithNA = TRUE)
一个错误?肯定没有重复?我无法理解为什么第一列必须是主键,当您可以自由地在&#39; by&#39;中指定它时。论点。
N.B出于某种原因,我现在无法复制原始的&#39;不是有效的列名称&#39;错误,尽管得到非常相似的数据!! (也用列重新排序固定)