简体   繁体   English

R,按列0合并数据帧

[英]R, Merge data frames by column 0

I've got 2 data frames containing timeseries(the time is not coded but there is time variable in column 0).The time variable in column zero doesn't allow to me to merge data frames. 我有2个包含时间序列的数据帧(时间没有编码,但在第0列有时间变量)。第0列的时间变量不允许我合并数据帧。 The data looks like this: TVC1 AND TVC2 (these are only 2 data frames out of 20) 数据如下所示:TVC1和TVC2(这些只是20个中的2个数据帧)

在此输入图像描述 在此输入图像描述

How can I create time variable or define column zero as time variable to merge the 20 data frames? 如何创建时间变量或将列零定义为时间变量以合并20个数据帧? Thanks, 谢谢,

there is a simple way to convert row names into the 1st column of your data using data.table 有一种简单的方法可以使用data.table将行名转换为数据的第一列

library(data.table)
setDT(df, keep.rownames = TRUE)[]

我们可以将数据集放在list ,然后与Reduce merge

Reduce(function(...) merge(..., by = "row.names"), mget(paste0("TVC", 1:20)))

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM