在没有公共密钥的情况下合并2个文件 [英] Merging 2 files without a common key

查看:69
本文介绍了在没有公共密钥的情况下合并2个文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有2个文件.一个是具有3000行的time_file,另一个是具有2000行的userid文件.我想将两者合并,以便userid文件中的每一行(ID)与time_file每行中的完整数据配对.

I have 2 files. One is a time_file which has 3000 rows and the other is userid file which has 2000 rows. I want to merge the two, so that each row (ID) in the userid file is paired with the full data from each row of the time_file.

第1-3000行将显示每个日期的第一个userid.

Rows 1-3000 would show the first userid with each of the dates.

第3001-6000行将显示带有每个日期的第二个userid,依此类推.

Rows 3001-6000 would show the 2nd userid with each of the dates, and so on.

提前谢谢!

时间文件

    mo  day year    date
    11  1   2015    11/1/2015
    11  2   2015    11/2/2015
    11  3   2015    11/3/2015
    11  4   2015    11/4/2015
    11  5   2015    11/5/2015
    .
    .

用户ID文件

userid
154
155
157
158
159
160
.
.

理想的格式(我想要什么)

Ideal format(what I want)

    mo  day year    date        userid
    11  1   2015    11/1/2015   154
    11  2   2015    11/2/2015   154
    11  3   2015    11/3/2015   154
    11  4   2015    11/4/2015   154
    11  5   2015    11/5/2015   154
    .
    .
    3   28  2017    3/28/2017   154
    3   29  2017    3/29/2017   154
    3   30  2017    3/30/2017   154
    3   31  2017    3/31/2017   154
    11  1   2015    11/1/2015   155
    11  2   2015    11/2/2015   155
    11  3   2015    11/3/2015   155
    11  4   2015    11/4/2015   155
    11  5   2015    11/5/2015   155
    11  6   2015    11/6/2015   155

推荐答案

我可以想到的R中最简单的解决方案,假设您已将时间数据存储在数据帧中,而用户数据存储在向量中:

Easiest solution in R I can think of, assuming you've gotten your time data in a data frame and your user data in a vector:

final_df <- cbind(date_df, "userid" = rep(user, each = 3000))

这将重复每个user_id 3000次,然后将user_id列绑定到日期数据框.

This will repeat each user_id 3000 times, then bind the user_id column to the date data frame.

这篇关于在没有公共密钥的情况下合并2个文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆