合并不同的数据集
Merge different dataset
我有一个问题,我需要将两个不同的数据集合并为一个,但它们有不同的 class。我该怎么办? 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)
您在找这样的东西吗?
nycounties@data = data.frame(nycounties@data,
df[match(nycounties@data[, "prov_name"],
df[, "city"]),])
输出
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
我有一个问题,我需要将两个不同的数据集合并为一个,但它们有不同的 class。我该怎么办? 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)
您在找这样的东西吗?
nycounties@data = data.frame(nycounties@data,
df[match(nycounties@data[, "prov_name"],
df[, "city"]),])
输出
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