Here is one way to do it.>
jen2<-reshape(jen,idvar="DNA",timevar="center",direction="wide")
This makes it easier to work with.
> jen2<-replace(jen2,jen2=="?",NA)
Change the question marks to NA.
> jen2$match1<-((jen2[,2]==jen2[,4])*1)
> jen2$match2<-((jen2[,3]==jen2[,5])*1)
> jen2
DNA snp1.1 snp2.1 snp1.2 snp2.2 match1 match2
1 NA07019 A A A A 1 1
2 NA07348 M G M G 1 1
3 NA10830 A G A G 1 1
4 NA10851 M G M G 1 1
5 NA10857 A G A G 1 1
6 NA10860 A G A G 1 1
7 NA10861 A G A G 1 1
8 NA12761 <NA> R A A NA
0> mean(jen2[,6:7])
match1 match2
NA 0.875 > mean(jen2[,6:7],na.rm=T)
match1 match2
1.000 0.875 >
-----Original Message-----
From: r-help-bounces at stat.math.ethz.ch
[mailto:r-help-bounces at stat.math.ethz.ch] On Behalf Of Tan Hui Hui Jenny
Sent: June 27, 2005 9:13 PM
To: r-help at stat.math.ethz.ch
Subject: [R] Crosstabs in R
HI,
I have the data in the following format. My aim is to determine the
concordance in genotype calls (SNP1, 2, 3,etc) at two centers.
DNA center snp1 snp2
NA07019 1 A A
NA07348 1 M G
NA10830 1 A G
NA10851 1 M G
NA10857 1 A G
NA10860 1 A G
NA10861 1 A G
NA12761 1 ? R
NA07019 2 A A
NA07348 2 M G
NA10830 2 A G
NA10851 2 M G
NA10857 2 A G
NA10860 2 A G
NA10861 2 A G
NA12761 2 A A
In SPSS, I would create individual crosstabulation tables and any
positive integer values (counts) falling outside of the diagonal are
disagreements in calls by the 2 centers (SNP2).
At SNP1, there are total of 7 genotype counts to compare (one DNA
did not have genotype readout). And 7/7 are in agreement.
At SNP2, all 8 DNA samples were successfully typed by both centers.
There is one discrepant call between centers.
Q1: how do I create the same crosstabs in R?
Eventually, I would summarize the data as follows:
SNP N_to_compare N_agreement %Concordance
snp1 7 7 100
snp2 8 7 87.5
etc
Q2: From the individual crosstabs tables, can I automatically
extract those numbers in columns 2 and 3?
rgds,
jenny
______________________________________________
R-help at stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide!
http://www.R-project.org/posting-guide.html