简体   繁体   English

合并不同的数据集

[英]Merge different dataset

I have a question, I need to merge two different dataset in one but they have a different class. How I can I do?我有一个问题,我需要将两个不同的数据集合并为一个,但它们有不同的 class。我该怎么做? rbind doesn't work, ideas? rbind 不起作用,想法?

nycounties <- rgdal::readOGR("https://raw.githubusercontent.com/openpolis/geojson-italy/master/geojson/limits_IT_provinces.geojson")

city <- c("Novara", "Milano","Torino","Bari")
dimension <- c("150000", "5000000","30000","460000")
df <- cbind(city, dimension)
 
total <- rbind(nycounties,df)

Are you looking for something like this?你在找这样的东西吗?

nycounties@data = data.frame(nycounties@data,
                             df[match(nycounties@data[, "prov_name"],
                                      df[, "city"]),])

Output Output

nycounties@data[!is.na(nycounties@data$dimension),]

   prov_name prov_istat_code_num prov_acr  reg_name reg_istat_code reg_istat_code_num prov_istat_code   city dimension
0     Torino                   1       TO  Piemonte             01                  1             001 Torino     30000
2     Novara                   3       NO  Piemonte             01                  1             003 Novara    150000
12    Milano                  15       MI Lombardia             03                  3             015 Milano   5000000
81      Bari                  72       BA    Puglia             16                 16             072   Bari    460000

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM