Reputation: 1655
I have data as shown below:
chr1 876499 A 517 G 948 A 353 G 964
chr1 877715 C 1166 G 883 C 555 G 944
chr1 877831 T 0 C 1 T 0 C 1
chr1 878314 G 933 C 666 G 89 C 106
chr1 878331 C 983 T 166 C 994 T 505
I would like to do fisher exact test, by making a matrix from columns 4,6,8 and 10 in the below shown way:
For example for first row:
u v
X 517 948
Y 353 964
It should calculate the Fisher-exact p-value, and add it as a new column to each row. Since im novice to R i do not have any code. Any help is valuable.
Thanks.
Upvotes: 0
Views: 971
Reputation: 1309
Try:
d.frm <- read.table(textConnection("
chr1 876499 A 517 G 948 A 353 G 964
chr1 877715 C 1166 G 883 C 555 G 944
chr1 877831 T 0 C 1 T 0 C 1
chr1 878314 G 933 C 666 G 89 C 106
chr1 878331 C 983 T 166 C 994 T 505
"))
d.frm$pval <- apply(as.matrix(d.frm[, c(4,6,8,10)]), 1,
function(x) fisher.test(matrix(x, nrow=2))$p.value)
Upvotes: 1