【问题标题】:how to access a data frame within a spatial data frame object?如何访问空间数据框对象中的数据框?
【发布时间】:2021-03-21 01:23:39
【问题描述】:

我在 R 中有一个名为 bikeracks.loadSpatialPointsDataFrame 对象,其中包含一个 名为bikeracks.load$Borough的数据框

然而,原始数据集在命名一个自治市镇时存在问题。

例如当我做unique(bikeracks.load$Borough)你可以看到

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

Manhattan 在某些行中的拼写不同。如何在 sp 数据框对象中访问此数据框并更正此问题?

【问题讨论】:

标签: r spatial-data-frame


【解决方案1】:

正如 Ronak 所说,您能给我们提供样本数据吗?如果您的空间数据与普通数据框不同,则基本 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)

【讨论】:

    猜你喜欢
    • 2021-11-15
    • 1970-01-01
    • 2020-01-11
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-12-28
    • 1970-01-01
    • 2016-08-16
    相关资源
    最近更新 更多