Matching values in columns in R [duplicate]

爱⌒轻易说出口 提交于 2019-12-11 17:41:19

问题


I have 2 large csv files that contain information about the same shops.

File1:

Dates1            Sales
02-11-2017        100
04-11-2017        90
01-08-2016        80
01-02-2013        99
01-09-2016        12

File2:

Dates2            Stores
02-11-2017        A
04-11-2017        B
01-09-2016        C

What I need is find the matching dates and create the following table:

NewDates          Stores  Sales
02-11-2017        A       100
04-11-2017        B       90
01-09-2016        C       12 

The files have different number of rows and the same date can be contained in a different row in the respecting file. Can you please help me solve this in R?


回答1:


library(data.table)

df1 <- fread("file1")
df2 <- fread("file2")

merge(df1, df2, by.x = 'Dates.1', by.y = 'Dates.2')

The data.table package can handled large files.



来源:https://stackoverflow.com/questions/48191031/matching-values-in-columns-in-r

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!