r - 如何在R中使用cbind合并两个csv?

标签 r cbind

我是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下。我究竟做错了什么?我没有通过任何键尝试(加入)任何数据。只需将两个文件合并为一个。

最佳答案

尝试:

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

关于r - 如何在R中使用cbind合并两个csv?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58434686/

相关文章:

arrays - R 中的数组要替换的项目数不是替换长度的倍数

r - 使用 purrr 创建 quosures 列表

r - 对列中的多个值使用ifelse语句

r - R reshape2 中 cast() 调用的自定义聚合函数出错

r - 在线性模型中结合 cbind 和 paste

r - 如何根据R中的行值添加新列?

R向量大小限制: "long vectors (argument 5) are not supported in .C"

r - 数据框选定列中包含 NA(缺失)值的行子集

r - 在 R 中通过 cbind 合并相同大小的行

r - 绑定(bind)具有不同行数的列