[R] Error when using anova(lm())

David Winsemius dwinsemius at comcast.net
Fri Oct 8 19:01:08 CEST 2010


On Oct 8, 2010, at 12:46 PM, Alison Callahan wrote:

> Hello all,
>
> I am trying to perform an ANOVA on some data in a data frame, but when
> I try to use lm(), I get the following error:
>
> Error in storage.mode(y) <- "double" :
>  invalid to change the storage mode of a factor
> In addition: Warning message:
> In model.response(mf, "numeric") :
>  using type="numeric" with a factor response will be ignored
>
> Here is a subset of my data:
>
>  island_id     refseq_better     total        refseq_proportion
> fiveprime   threeprime        island_size
>       1a            29                  57          0.508771929824561
>    11127     201378               190251
>       1c            27                  90               0.3
>             6303879    6600994            297115
>       1d            33                 115         0.28695652173913
>  7001283    7421591            420308
>       2b            11                  42          0.261904761904762
>  4381375    4520137            138762
>       2d            27                  81          0.333333333333333
>  5203929    5497271            293342
>       3a            44                 141         0.312056737588652
>   28792      552044              523252
>
> When I use sapply(dataframe,mode) to check the modes of the columns,
> this is my output:
>
>       island_id     refseq_better             total         
> refseq_proportion
>        "numeric"         "numeric"         "numeric"         "numeric"
>        fiveprime        threeprime       island_size
>        "numeric"         "numeric"         "numeric"

So?

 > mode(factor(1:10))
[1] "numeric"

Storage mode is not the right question. "class" is the correct  
question. Best would be to try is.factor()


> How do I need to change the format of my data frame so that I do not
> get the above error?

Figure out which of your columns are factors and apply the FAQ 7.12

-- 
David.
>
> Thanks!
>
> Alison Callahan
> PhD candidate


David Winsemius, MD
West Hartford, CT



More information about the R-help mailing list