Quantcast

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

classic Classic list List threaded Threaded
5 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate
star

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

Jason Love
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")

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

        [[alternative HTML version deleted]]

______________________________________________
[hidden email] 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.
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate
star

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

Michael Weylandt
On Wed, Sep 12, 2012 at 4:04 PM, Jason Love <[hidden email]> 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]]
>
> ______________________________________________
> [hidden email] 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.

______________________________________________
[hidden email] 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.
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate
star

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

Bert Gunter
In reply to this post by Jason Love
Have you read (relevant sections) of "An Introduction to R"  to gain
some basic understanding of how R works? If not, please do so before
further posting.

Briefly, Var is a data frame and rcorr wants a matrix.

-- Bert

On Wed, Sep 12, 2012 at 8:04 AM, Jason Love <[hidden email]> 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")
>
> Error in storage.mode(x) <- if (.R.) "double" else "single" :
>   (list) object cannot be coerced to type 'double'
>
>         [[alternative HTML version deleted]]
>
> ______________________________________________
> [hidden email] 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.



--

Bert Gunter
Genentech Nonclinical Biostatistics

Internal Contact Info:
Phone: 467-7374
Website:
http://pharmadevelopment.roche.com/index/pdb/pdb-functional-groups/pdb-biostatistics/pdb-ncb-home.htm

______________________________________________
[hidden email] 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.
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate
star

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

Rui Barradas
In reply to this post by Michael Weylandt
Hello,

The input must be a matrix, not a list (or its special case data.frame).

Var <- read.table(text="
   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
", header=TRUE)

# library(Hmisc)
rc <- rcorr(as.matrix(Var), type="pearson")
# from recommended package stats
ct <- cor.test(Var$D.Prime, Var$T.statistics, method = "pearson")

rc$P
                D.Prime T.statistics
D.Prime             NA    0.1101842
T.statistics 0.1101842           NA

ct$p.value
[1] 0.1101842

To the op: you should say which library you are using. Even if Hmisc is
a very popular one.

Hope this helps,

Rui Barradas


Em 12-09-2012 16:10, R. Michael Weylandt escreveu:

> On Wed, Sep 12, 2012 at 4:04 PM, Jason Love <[hidden email]> 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]]
>>
>> ______________________________________________
>> [hidden email] 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.
> ______________________________________________
> [hidden email] 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.

______________________________________________
[hidden email] 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.
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate
star

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

Jason Love
thanks all for the prompt answer.
Yes, I need to go through the R tutorial rather than learning a snippet of
codes from googling.


On Wed, Sep 12, 2012 at 11:32 AM, Rui Barradas <[hidden email]> wrote:

> Hello,
>
> The input must be a matrix, not a list (or its special case data.frame).
>
> Var <- read.table(text="
>   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
> ", header=TRUE)
>
> # library(Hmisc)
> rc <- rcorr(as.matrix(Var), type="pearson")
> # from recommended package stats
> ct <- cor.test(Var$D.Prime, Var$T.statistics, method = "pearson")
>
> rc$P
>                D.Prime T.statistics
> D.Prime             NA    0.1101842
> T.statistics 0.1101842           NA
>
> ct$p.value
> [1] 0.1101842
>
> To the op: you should say which library you are using. Even if Hmisc is a
> very popular one.
>
> Hope this helps,
>
> Rui Barradas
>
>
> Em 12-09-2012 16:10, R. Michael Weylandt escreveu:
>
>  On Wed, Sep 12, 2012 at 4:04 PM, Jason Love <[hidden email]>
>> 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]]
>>>
>>> ______________________________**________________
>>> [hidden email] mailing list
>>> https://stat.ethz.ch/mailman/**listinfo/r-help<https://stat.ethz.ch/mailman/listinfo/r-help>
>>> PLEASE do read the posting guide http://www.R-project.org/**
>>> posting-guide.html <http://www.R-project.org/posting-guide.html>
>>> and provide commented, minimal, self-contained, reproducible code.
>>>
>> ______________________________**________________
>> [hidden email] mailing list
>> https://stat.ethz.ch/mailman/**listinfo/r-help<https://stat.ethz.ch/mailman/listinfo/r-help>
>> PLEASE do read the posting guide http://www.R-project.org/**
>> posting-guide.html <http://www.R-project.org/posting-guide.html>
>> and provide commented, minimal, self-contained, reproducible code.
>>
>
>

        [[alternative HTML version deleted]]

______________________________________________
[hidden email] 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.
Loading...