使用R将制表符分隔文件合并成单个文件 [英] Combining tab delim files into a single file using R

查看:221
本文介绍了使用R将制表符分隔文件合并成单个文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有几个txt文件,每个文件中有3列,如下所示:
文件1:

I have several txt files with 3 columns in each files like this: file 1:

ProbeID X_Signal_intensity X_P-Value   
xxx         2.34          .89
xxx         6.45          .04 
xxx         1.09          .91  
xxx         5.87          .70
.            .            . 
.            .            .
.            .            .     

文件2:

ProbeID Y_Signal_intensity Y_P-Value   
xxx         1.4             .92
xxx         2.55            .14 
xxx         4.19            .16  
xxx         3.47            .80
.            .               . 
.            .               .
.            .               . 

文件3:

ProbeID Z_Signal_intensity Z_P-Value   
xxx         9.40             .82
xxx         1.55            .04 
xxx         3.19            .56  
xxx         2.47            .90
.            .               . 
.            .               .
.            .               . 

在所有上述文件中,ProbeID列的值相同,但不是其他列。将使用 for-loop 的所有上述文件合并到单个文件中,如下所示:

In all the above files the values of ProbeID column are identical but not the other columns.Now I want to combine the all the above files using a for-loop into a single file like this:

ProbeID X_intensity X_P-Value   Y_intensity Y_P-Value   Z_intensity Z_P-Value     
xxx      2.34          .89       1.4             .92     9.40            .82
xxx      6.45          .04       2.55            .14     1.55            .04
xxx      1.09          .91       4.19            .16     3.19            .56
xxx      5.87          .70       3.47            .80     2.47            .90

请做帮助我。

推荐答案

我的方法是将文件读入data.frames

My approach is to read the files into data.frames

请参阅 help(read.delim)阅读模式。

您有三个数据后。可以使用的框架

After you have your three data.frames you can use

total <- merge(dataframeA,dataframeB,by="ProbeID")

看这里 http://www.statmethods.net/management/merging.html 的文档。

这篇关于使用R将制表符分隔文件合并成单个文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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