i'm using the raster::subs function to replace values in a raster with values in a data.table (and data.frame), using a primary key, but am getting the errors:
Error in .local(x, y, ...) : 'by' is not a valid column name
and sometimes;
Error in .local(x, y, ...) : duplicate "by" values not allowed
example:
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
the following work:
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)
a bug? surely there are no duplicates? I can't see why the first column must be the primary key when you have the freedom to specify it in the 'by' argument.
N.B for some reason I now cannot duplicate the original 'not a valid column name' error, despite getting it on very similar data!! (also fixed with column reorder)