[英]how to access a data frame within a spatial data frame object?
我在 R 中有一个SpatialPointsDataFrame
object,名为bikeracks.load
,其中有一个名为bikeracks.load$Borough
的 dataframe
然而,原始数据集在命名一个自治市镇时存在问题。
例如,当我做unique(bikeracks.load$Borough)
你可以看到
"Brooklyn" "Bronx" "Manhattan" "manhattan" "Queens" "Staten Island"
曼哈顿在某些行中的拼写不同。 如何在 sp dataframe object 中访问此 dataframe 并更正此问题?
正如 Ronak 所说,你能给我们提供样本数据吗? 如果您的空间数据与普通的dataframe差别不大,那么基本的 R 方法将是:
bikeracks.load[bikeracks.load$Borough=="manhattan",]$Borough <- "Manhattan"
使用 IRIS 数据进行测试:
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)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.