10
votes

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
)

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.

Thanks, Sharad

1
dat <- merge(dat, pheno, by.x = "sid", by.y = "sen", all=TRUE) - Ista
For latter use, don't miss the snpMatrix (efficient storage of genotype data, fast GLMs), snpAssoc (user-friendly), or GenABEL packages. Most allow to build specific structure (or environment, with GGtools) for manipulating and merging genotype and phenotype data. - chl
@Ista, next time post as an answer. That way, you can be rewarded in a little way. - Roman Luštrik

1 Answers

9
votes

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

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