avoid within table correlations in rcorr
I´m building a correlation between two different matrices(coding-lncoding) with rcorr() function in R,how can I remove within table correlations?is there any way or I should remove them by hand?
• 3,405 views
•
link
1 answer
Hello,
You can try this:
table1 <- matrix(rnorm(25),5)
table2 <- matrix(rnorm(25),5)
cor.matrix <- rcorr(table1, table2, type="pearson")
P <- data.frame(cor.matrix$P)
R <- data.frame(cor.matrix$r)
# Data frame with p values
P.df <- P[,-c(1:ncol(table1))]
P.df <- P.df[-c((ncol(table1))+1:ncol(P)),]
P.df
# Data frame with r values
R.df <- R[,-c(1:ncol(table1))]
R.df <- R.df[-c((ncol(table1))+1:ncol(R)),]
R.df
Grts
• 0 views
•
link
Log in to answer this question.
What specifically do you call within table correlation?
see this table that made by another person:
table1 <- matrix(rnorm(25),5)
table2 <- matrix(rnorm(25),5)
res <- rcorr(table1, table2, type="pearson") res
Notice the upper right quadrant of rcorr() (which repeats diagonally symmetrical on lower left) is the entire result of cor() (rounded to two decimal points)
res <- cor(table1, table2, method="pearson")
res
I want the correlation like core result,I need p-value so I used rcorr() function.