匹配R中列中的值 [英] Matching values in columns in R
本文介绍了匹配R中列中的值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有2个大型csv文件,其中包含有关同一商店的信息.
I have 2 large csv files that contain information about the same shops.
文件1:
Dates1 Sales
02-11-2017 100
04-11-2017 90
01-08-2016 80
01-02-2013 99
01-09-2016 12
文件2:
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
文件具有不同的行数,并且相同日期可以包含在相关文件的不同行中.您能帮我解决R中的问题吗?
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?
推荐答案
library(data.table)
df1 <- fread("file1")
df2 <- fread("file2")
merge(df1, df2, by.x = 'Dates.1', by.y = 'Dates.2')
data.table
包可以处理大文件.
这篇关于匹配R中列中的值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文