[R] how to export results of rcorr into excel

Dieter Menne dieter.menne at menne-biomed.de
Tue Nov 11 18:51:05 CET 2008


shixin <jasonshi510 <at> hotmail.com> writes:

> 
> I try to export the outputs of rcorr into excel. but I got error
message,"cannot coerce class "rcorr" into a
> data.frame". Actually i just need export part of results of this analysis,e.g.
p-values or stat-values.
library(Hmisc)
x <- c(-2, -1, 0, 1, 2)
y <- c(4,   1, 0, 1, 4)
z <- c(1,   2, 3, 4, NA)
v <- c(1,   2, 3, 4, 5)
rc = rcorr(cbind(x,y,z,v))

str(rc) gives

List of 3
 $ r: num [1:4, 1:4] 1 0 1 1 0 ...
  ..- attr(*, "dimnames")=List of 2
  .. ..$ : chr [1:4] "x" "y" "z" "v"
  .. ..$ : chr [1:4] "x" "y" "z" "v"
 $ n: int [1:4, 1:4] 5 5 4 5 5 5 4 5 4 4 ...
  ..- attr(*, "dimnames")=List of 2
  .. ..$ : chr [1:4] "x" "y" "z" "v"
  .. ..$ : chr [1:4] "x" "y" "z" "v"
 $ P: num [1:4, 1:4] NA 1 0 0 1 ...
  ..- attr(*, "dimnames")=List of 2
  .. ..$ : chr [1:4] "x" "y" "z" "v"
  .. ..$ : chr [1:4] "x" "y" "z" "v"
 - attr(*, "class")= chr "rcorr"


 So you could write.table or whatever on
 rc$r
 rc$n
 rc$P
 
 Dieter



More information about the R-help mailing list