I have a SpatialPolygonsDataFrame in R, from which I would like to extract a vector of one of the columns. This can be done easily by using the $
notation, e.g. dataFrame$columnName
. My code however needs to pass the column names as strings, in which case I would normally use the bracket notation dataFrame[,'columnName']
to get the same result. R-spatial however, per the documentation, doesn't seem to allow this, returning instead a full SpatialPolygonsDataFrame object with geometry added to the single requested column.
How can I go from a string of the column name to just a vector of the data in that column? I'd prefer to do this without creating a separate non-spatial dataframe if possible.