[R] How to resolve the following error: (list) object cannot be coerced to type 'double'

R. Michael Weylandt michael.weylandt at gmail.com
Wed Sep 12 17:10:12 CEST 2012


On Wed, Sep 12, 2012 at 4:04 PM, Jason Love <jason.love1492 at gmail.com> wrote:
> Hello,
> I'd like to test a significance of two variables in their correlation using
> rcorr, which gave me an error of format incompatibility.
> Below are the lines that I typed in the R window and let me know if anyone
> knows how to resolve this.
>
> Var=read.csv("03apr10ab_corr_matrix_in_overlaps.csv",header=F)
> colnames(Var)=c("D Prime","T statistics")
>
>          D Prime    T statistics
> 1    1.7234e-01     4.926800
> 2    1.4399e-01     2.892000
> 3    1.4626e-01     2.642800
> 4    3.5147e-02     1.112400
> 5    5.8957e-02     2.723700
>
>
> rcorr(Var, type="pearson")

Untested (because I'm still without respectable internet after a move)
I believe rcorr would rather have a matrix than a data.frame(), which
is what read.csv produces, so try

Var <- as.matrix(Var)

or

rcorr(as.matrix(Var), type = "pearson")

>
> Error in storage.mode(x) <- if (.R.) "double" else "single" :
>   (list) object cannot be coerced to type 'double'

This suggests that the input to rcorr is being converted to a double,
which isn't a valid storage.mode change for a list (= data frame).

Cheers,
M

>
>         [[alternative HTML version deleted]]
>
> ______________________________________________
> 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.




More information about the R-help mailing list