[R] Hmisc::rcorr on a 'data.frame'?

Frank Harrell f.harrell at vanderbilt.edu
Sat Aug 20 02:58:45 CEST 2011


I don't see anything wrong with using as.matrix.  The documentation doesn't
say it will support a data frame.
Frank

Liviu Andronic wrote:
> 
> Dear all
> ?Hmisc::rcorr states that it takes as main argument "a numeric
> matrix". But is it normal that it fails in such an ugly way on a data
> frame? (See below.) If the function didn't attempt any conversion to a
> matrix, I would have expected it to state that in the error message
> that it didn't accept 'data.frame' objects in its input. Also, I
> vaguely remember having used in the past rcorr() on data frames.
> 
> Regards
> Liviu
> 
>> require(Hmisc)
>> rcorr(mtcars[ , 1:4])
> Error in storage.mode(x) <- if (.R.) "double" else "single" :
>   (list) object cannot be coerced to type 'double'
>> rcorr(as.matrix(mtcars[ , 1:4]))
>        mpg   cyl  disp    hp
> mpg   1.00 -0.85 -0.85 -0.78
> cyl  -0.85  1.00  0.90  0.83
> disp -0.85  0.90  1.00  0.79
> hp   -0.78  0.83  0.79  1.00
> 
> n= 32
> 
> 
> P
>      mpg cyl disp hp
> mpg       0   0    0
> cyl   0       0    0
> disp  0   0        0
> hp    0   0   0
> 
> 
> 
> 
> -- 
> Do you know how to read?
> http://www.alienetworks.com/srtest.cfm
> http://goodies.xfce.org/projects/applications/xfce4-dict#speed-reader
> Do you know how to write?
> http://garbl.home.comcast.net/~garbl/stylemanual/e.htm#e-mail
> 
> ______________________________________________
> R-help at 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.
> 


-----
Frank Harrell
Department of Biostatistics, Vanderbilt University
--
View this message in context: http://r.789695.n4.nabble.com/Hmisc-rcorr-on-a-data-frame-tp3755868p3756462.html
Sent from the R help mailing list archive at Nabble.com.



More information about the R-help mailing list