Angel Russo
2013-Jun-24 11:09 UTC
[R] help needed with printing multiple arguments as vectors, not matrices
** I am using the following way to get p-values from fiser exact test. However, I do need to print for each pair the values "n00, n01, n10, n11". How can I print that as a table and not a matrix as below along with the p-value? Any help will be greatly appreciated fish <- function(y, x) {n00 = sum((1-x)*(1-y)); n01 = sum((1-x)*y); n10 = sum(x*(1-y)); n11 = sum(x*y); a = matrix(c(n00, n01, n10, n11), nrow = 2); pval = fisher.test(a)$p.value; return(pval);} chiArray <- function(x) { apply(mat1, 1, fish, x); } sapply(1:nrow(mat2), function(j){chiArray(mat2[j, ]);}); chisq.cna.mut.test <- sapply(1:nrow(mat2), function(j){chiArray(mat2[j, ]);}); I want output to be: name1_mat1 name1_mat2 n00 n01 n10 n11 pvalue name1_mat1 name2_mat2 n00 n01 n10 n11 pvalue [[alternative HTML version deleted]]
Adams, Jean
2013-Jun-24 15:03 UTC
[R] help needed with printing multiple arguments as vectors, not matrices
Could you provide an example of mat1 and mat2 as well as an example of the output you would like from them. Your code is very difficult to follow as written. It will be easier for readers of the list to interpret if you use carriage returns rather than semi colons, for example ... fish <- function(x, y) { n00 = sum((1-x)*(1-y)) n01 = sum((1-x)*y) n10 = sum(x*(1-y)) n11 = sum(x*y) a = matrix(c(n00, n01, n10, n11), nrow=2) pval = fisher.test(a)$p.value return(pval) } Jean On Mon, Jun 24, 2013 at 6:09 AM, Angel Russo <angerusso1980@gmail.com>wrote:> ** > > I am using the following way to get p-values from fiser exact test. > However, I do need to print for each pair the values "n00, n01, n10, n11". > How can I print that as a table and not a matrix as below along with the > p-value? Any help will be greatly appreciated > > fish <- function(y, x) {n00 = sum((1-x)*(1-y)); n01 = sum((1-x)*y); > n10 = sum(x*(1-y)); n11 = sum(x*y); a = matrix(c(n00, n01, n10, n11), > nrow = 2); pval = fisher.test(a)$p.value; return(pval);} > > chiArray <- function(x) { apply(mat1, 1, fish, x); } > sapply(1:nrow(mat2), function(j){chiArray(mat2[j, ]);}); > chisq.cna.mut.test <- sapply(1:nrow(mat2), function(j){chiArray(mat2[j, > ]);}); > > I want output to be: > > name1_mat1 name1_mat2 n00 n01 n10 n11 pvalue > > > > name1_mat1 name2_mat2 n00 n01 n10 n11 pvalue > > [[alternative HTML version deleted]] > > ______________________________________________ > R-help@r-project.org mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide > http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code. >[[alternative HTML version deleted]]