Grant Gillis wrote: > Hi Thibaut, > > Thanks for having a look at this for me. What you have is close to what I'm > looking for. Where I am stuck is that for me each data sheet does not > necessarily have the same individuals. I have in the range of 20 different > data sheets composed of various formulations of 200 individuals. Not all > individuals are in every sheet. Each sheet has a column for individuals and > columns for allele data from 2 or 3 microsatillate loci. I would like to > read these into a data sheet that has all individual and locus data in a > single sheet with a column of individuals and 2 columns per locus for > microsat data. > > I have done this the old-fashioned way in excel (with vlookup) but will have > to do it again a few more times in the future do if it is relatively simple > I am still interested in and suggestions on how it can be done. > > Cheers > Grant > > > > > So from your example it would be closer to: > >> A <- matrix(1:12, ncol=3) >> B <- matrix(12:1, ncol=3) >> rownames(A) <- letters[1:4] >> rownames(B) <- letters[6:3] >> A > [,1] [,2] [,3] > a 1 5 9 > b 2 6 10 > c 3 7 11 > d 4 8 12 >> B > [,1] [,2] [,3] > f 12 8 4 > e 11 7 3 > d 10 6 2 > c 9 5 1
All right, then I guess what you need is using merge. >From your example above: > A <- data.frame(id=rownames(A),A) > B <- data.frame(id=rownames(B),B) > A id V1 V2 V3 a a 1 5 9 b b 2 6 10 c c 3 7 11 d d 4 8 12 > B id X1 X2 X3 f f 12 8 4 e e 11 7 3 d d 10 6 2 c c 9 5 1 ## only common individuals > merge(A,B, by="id") id V1 V2 V3 X1 X2 X3 1 c 3 7 11 9 5 1 2 d 4 8 12 10 6 2 ## all individuals > merge(A,B, by="id", all=TRUE) id V1 V2 V3 X1 X2 X3 1 a 1 5 9 NA NA NA 2 b 2 6 10 NA NA NA 3 c 3 7 11 9 5 1 4 d 4 8 12 10 6 2 5 e NA NA NA 11 7 3 6 f NA NA NA 12 8 4 Definitely no need to use excel here ;-) Cheers, Thibaut. -- ###################################### Dr Thibaut JOMBART MRC Centre for Outbreak Analysis and Modelling Department of Infectious Disease Epidemiology Imperial College - Faculty of Medicine St Marys Campus Norfolk Place London W2 1PG United Kingdom Tel. : 0044 (0)20 7594 3658 [email protected] http://biomserv.univ-lyon1.fr/%7Ejombart/ http://adegenet.r-forge.r-project.org/ [[alternative HTML version deleted]]
_______________________________________________ R-sig-genetics mailing list [email protected] https://stat.ethz.ch/mailman/listinfo/r-sig-genetics
