Tuesday, 15 January 2013

r - cannot handle matrix/array columns with write.dbf -



r - cannot handle matrix/array columns with write.dbf -

hope problem. first time me , it's little bit tricky describe.

i want add together attributes dbf file , save afterwards utilize in qgis. elections , info votes 11 parties in absolute , relative values. utilize shapefiles bundle this, tried foreign.

my system: rstudio 0.97.311, r 2.15.2, shapefile 0.7, foreign 0.8-52, ubuntu 12.04

try #1 => no problems

shpdistricts <- read.shapefile(filename) shpdatadistricts <- shpdistricts$dbf[[1]] shpdatadistricts <- shpdatadistricts[, -c(3, 4, 5)] # delete columns shpdistricts$dbf[[1]] <- shpdatadistricts write.shapefile(shpdistricts, filename))

try #2 => "error in get("write.dbf", "package:foreign")(dbf$dbf, out.name) : cannot handle matrix/array columns"

shpdistricts <- read.shapefile(filename) shpdatadistricts <- shpdistricts$dbf[[1]] shpdatadistricts <- shpdatadistricts[, -c(3, 4, 5)] # delete columns shpdatadistricts <- cbind(shpdatadistricts, votesdistrict[, 2]) # add together new column names(shpdatadistricts)[5] <- "spoe" shpdistricts$dbf[[1]] <- shpdatadistricts write.shapefile(shpdistricts, filename))

the write function returns "error in get("write.dbf", "package:foreign")(dbf$dbf, out.name) : cannot handle matrix/array columns"

so adding column (integer) data.frame, write.dbf function isn't able write out anymore. debugging 3 hours on simple issue. tried shapefiles bundle via opening shapefile , dbf file, time same problem.

when utilize foreign bundle straight (read.dbf).

if save dbf-file without voting info (only little adapations step 1+2), it's no problem. must have merge voting data.

i got same error message ("error in get("write.dbf"...) while working shapefiles in r using rgdal. added column shapefile, tried save output , got error. added column shapefile dataframe, when converted factor via as.factor() error went away.

shapefile$column <- as.factor(additional.column)

writepolyshape(shapefile, filename)

r gis spatial shapefile dbf

No comments:

Post a Comment