how to access a data frame within a spatial data frame object?

200 Views Asked by At

I have a SpatialPointsDataFrame object in R called bikeracks.load which has within it a dataframe called bikeracks.load$Borough

The original dataset however has an issue with naming one of the borough's.

For instance when i do unique(bikeracks.load$Borough)you can see that

"Brooklyn"      "Bronx"         "Manhattan"     "manhattan"     "Queens"        "Staten Island"

Manhattan is spelt differently in some of the rows. how can I access this dataframe within the sp dataframe object and correct this?

1

There are 1 best solutions below

0
M.Viking On

As Ronak says, can you give us sample data? If your spatial data is not too different from a normal dataframe, then the base R method would be:

bikeracks.load[bikeracks.load$Borough=="manhattan",]$Borough <- "Manhattan"

Tested with IRIS data:

iris4<-data.frame(iris, stringsAsFactors = FALSE)
iris4$Species<-as.character(iris4$Species) #get rid of pesky factor from default iris.
unique(iris4$Species)
iris4[iris4$Species=="virginica",]$Species<-"test"
unique(iris4$Species)