Skip to content

Feature Request: rownames= option for setDF #1320

@MichaelChirico

Description

@MichaelChirico

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)])

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions