将CSV文件合并为1个具有不同列的文件

时间:2019-04-03 15:06:16

标签: r csv statistics bioinformatics

我有3个大型csv文件(OCA1 = 3649个观测值,521个变量,OCA2 = 3772个观测值,2513个变量,OCA3 = 878个观测值,2513个变量)。我想将它们合并到R中的1个csv文件中。我唯一关心的是它们具有不同的列,但是,每个文件的前10列是相同的。这是一个示例:

OCA1: enter image description here

OCA2: enter image description here

如您所见,直到“格式”(Format)为止,列名都是相同的。我想要的是所需的输出,如下所示:

C-x k

在最后一次观察到OCA1之后,将OCA2中“格式”之后的列添加到OCA1中,并将OCA2中的行添加到其中。

我最初尝试使用rbind,但是由于列的原因,我很挣扎。

2 个答案:

答案 0 :(得分:0)

bind_rows中的

dplyr可以帮助绑定具有不同列数的数据集。这是一个示例:

library(dplyr)

OCA1 <- data_frame(
  x = 1:3
)

OCA2 <- data_frame(
  x = 1:5,
  y = letters[1:5]
)

OCA3 <- data_frame(
  x = 1:10,
  y = letters[1:10],
  z = LETTERS[1:10]
)

df <- bind_rows(
  OCA1,
  OCA2,
  OCA3
)

答案 1 :(得分:0)

也许您可以为缺失的列创建NA列,然后进行rbind

<ion-list>
// Loop the results 
<ion-item *ngFor="let protocole of protocoles">

    <ng-template[ngIf]="{{value}}=={{other_value}}">
    <div>
        <ion-label>
            <h2>{{ protocole.item}} {{ modal_data_prot_detail_code }}</h2>
        </ion-label> 
    </div>

    // ELSE
    </ng-template>
        <ion-label"><h2>{{ protocole.item}}}</h2> </ion-label>
    </ion-list>
相关问题