Hi,
For computing correlation among variables in a matrix, I use cor( ), but for computing the p-values I'm using cor.test in the following way:


cor.p <- function(X)
{
res <- matrix(0, ncol(X), ncol(X))
for (i in 1:ncol(X))
for (j in 1:ncol(X)) res[i, j]<- cor.test(X[, i], X[, j])$p.value
rownames(res) <- colnames(res) <- colnames(X)
res
}

I'm just wondering if there is a better (nicer) way to do the same.
For example, would it be possible to use apply() with cor.test instead of using the for loops?
I'm trying to improve my low R skills.
Thanks


Juli

______________________________________________
[EMAIL PROTECTED] mailing list
https://www.stat.math.ethz.ch/mailman/listinfo/r-help

Reply via email to