简体   繁体   English

合并 R 中的两个数据帧

[英]merging two dataframes in R

I have data in a dataframe with 139104 rows which is multiple of 96x1449.我在 dataframe 中有数据,有 139104 行,是 96x1449 的倍数。 i have a phenotype file which contains the phenotype information for the 96 samples.我有一个表型文件,其中包含 96 个样本的表型信息。 the snp name is repeated 1449X96 samples. snp 名称重复 1449X96 个样本。 I haveto merge the two dataframes based on sid and sen.我必须基于 sid 和 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
)

I have to merge or add the disease column and 3 other columns to the data file.我必须将疾病列和其他 3 列合并或添加到数据文件中。 I am unable to use merge in R.我无法在 R 中使用合并。 I have searched google, i am not hitting the correct terms to get the answer.我已经搜索了谷歌,我没有找到正确的术语来获得答案。 I would appreciate any input on this issue.我将不胜感激有关此问题的任何意见。

Thanks, Sharad谢谢,沙拉德

You can specify the columns you want to match on directly with merge() :您可以使用merge()直接指定要匹配的列:

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

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

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