Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature Request: rownames= option for setDF #1320

Closed
MichaelChirico opened this issue Sep 9, 2015 · 1 comment
Closed

Feature Request: rownames= option for setDF #1320

MichaelChirico opened this issue Sep 9, 2015 · 1 comment

Comments

@MichaelChirico
Copy link
Member

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

@arunsrinivasan
Copy link
Member

rownames argument accepting a vector makes sense. PR would be great.

arunsrinivasan added a commit that referenced this issue Sep 11, 2015
Closes #1320; setDF gains the rownames argument
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants