我是R和SO的新手:
我有两个csv数据帧:
MyData1 <- read.csv(file="AddressListGeocoded.csv", header=TRUE, sep=",")
MyData2 <- read.csv(file="AddressListToGeocode_output28732.csv", header=TRUE, sep=",")
一个csv看起来像这样(reprex):
head(MyData1)
AddressId StreetAddressLine1 City ZipCode StateAbbreviation Latitude
1 60350 119 Summit Ave Winthrop 2152 MA 42.38445
2 6955669 1705 Chaise Ct Carson City 89703 NV 39.17730
3 6956266 13 Phillips Ave Shrewsbury 1545 MA 42.28119
4 6997538 38003 Wheeler Rd Dexter 97431 OR 43.94063
5 6956697 3919 Birkdale Ln Se Olympia 98501 WA 46.99440
6 6955879 117 Highland Ave Staten Island 10301 NY 40.61681
Longitude GeocodeSource MatchDescription
1 -70.97491 Redpoint NA
2 -119.77846 Redpoint NA
另一个:
head(MyData2)
AddressId StreetAddressLine1 Latitude Longitude GeocodeSource
1 6956755 10640 Ashby Place, 22030, VA 38.84230 -77.31478 arcgis
2 6956815 11328 Sandestin Place, 20695, MD 38.56669 -76.92166 arcgis
3 6956453 199 North 8th Street, 18045, PA 40.74550 -75.26121 arcgis
4 6957143 645 Via Trepadora, 93110, CA 34.43254 -119.77084 arcgis
我尝试了
> AddressMaster <- cbind(MyData1,MyData2)
Error in data.frame(..., check.names = FALSE) :
arguments imply differing number of rows: 9956, 28732
但是我收到了以上错误。我的目标是使MyData2中的所有行都在单个合并文件中的Mydata1下。我究竟做错了什么?我没有通过任何键尝试(加入)任何数据。只需将两个文件合并为一个。
答案 0 :(得分:0)
尝试:
library(dplyr)
MyData1 <- as.tibble(MyData1)
MyData2 <- as.tibble(MyData2)
res <- dplyr::full_join(MyData1, MyData2, by = "AddressId")
在此处查看更多信息: https://rstudio.com/wp-content/uploads/2015/02/data-wrangling-cheatsheet.pdf