You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I'm trying to play along with this vignette on combining spatial data by Roger Bivand & have run into the thorny issue that Spatial* objects (most importantly SpatialPolygons) depend on a data.frame's row names to communicate between the IDs used for plotting & the associated data.
So while it's handy to have sp@data as a data.table for various operations where I'm comfortable using data.table syntax (merging, adding/dropping columns, etc.), I found that I needed setDF at a step used to match a Spatial* object's IDs to its data (specifically these lines on page 3: row.names(nc90_df) <- paste(nc90_df$ST, nc90_df$CO, sep = ""); nc90b <- SpatialPolygonsDataFrame(nc90a, nc90_df)).
I was thinking it would be convenient for setDF to have an argument, rownames parallel to setDT's keep.rownames to simultaneously assign non-sequential row names to the result, ideally (for parsimony) evaluating within the data.table's environment, e.g. setDF(sp@data, rownames = paste0(ST, CO)), though explicitly calling the data.table environment would also be simple: setDF(sp@data, rownames = sp@data[, paste0(ST, CO)])
The text was updated successfully, but these errors were encountered:
I'm trying to play along with this vignette on combining spatial data by Roger Bivand & have run into the thorny issue that
Spatial*
objects (most importantlySpatialPolygons
) depend on adata.frame
's row names to communicate between the IDs used for plotting & the associated data.So while it's handy to have
sp@data
as adata.table
for various operations where I'm comfortable usingdata.table
syntax (merging, adding/dropping columns, etc.), I found that I neededsetDF
at a step used to match aSpatial*
object's IDs to its data (specifically these lines on page 3:row.names(nc90_df) <- paste(nc90_df$ST, nc90_df$CO, sep = ""); nc90b <- SpatialPolygonsDataFrame(nc90a, nc90_df)
).I was thinking it would be convenient for
setDF
to have an argument,rownames
parallel tosetDT
'skeep.rownames
to simultaneously assign non-sequential row names to the result, ideally (for parsimony) evaluating within thedata.table
's environment, e.g.setDF(sp@data, rownames = paste0(ST, CO))
, though explicitly calling thedata.table
environment would also be simple:setDF(sp@data, rownames = sp@data[, paste0(ST, CO)])
The text was updated successfully, but these errors were encountered: