在R中合并两个数据帧 [英] merging two dataframes in R

查看:29
本文介绍了在R中合并两个数据帧的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的数据帧中有 139104 行数据,是 96x1449 的倍数.我有一个表型文件,其中包含 96 个样本的表型信息.snp 名称重复 1449X96 个样本.我必须基于 sid 和 sen 合并两个数据帧.这是我的两个数据框的样子

I have data in a dataframe with 139104 rows which is multiple of 96x1449. i have a phenotype file which contains the phenotype information for the 96 samples. the snp name is repeated 1449X96 samples. I haveto merge the two dataframes based on sid and sen. this is how my two dataframes look like

dat <- data.frame(
    snpname=rep(letters[1:12],12),
    sid=rep(1:12,each=12), 
    genotype=rep(c('aa','ab','bb'), 12)
)
pheno <- data.frame(
    sen=1:12,
    disease=rep(c('N','Y'),6), 
    wellid=1:12
)

我必须将疾病列和其他 3 列合并或添加到数据文件中.我无法在 R 中使用合并.我已经搜索过谷歌,我没有找到正确的术语来获得答案.如果您对此问题有任何意见,我将不胜感激.

I have to merge or add the disease column and 3 other columns to the data file. I am unable to use merge in R. I have searched google, i am not hitting the correct terms to get the answer. I would appreciate any input on this issue.

谢谢,莎拉德

推荐答案

您可以直接使用 merge() 指定要匹配的列:

You can specify the columns you want to match on directly with merge():

merge(dat, pheno, by.x = "sid", by.y = "sen")

这篇关于在R中合并两个数据帧的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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