Re: [R] where did the factor name go

From: Prof Brian Ripley <ripley_at_stats.ox.ac.uk>
Date: Tue, 29 May 2007 06:59:08 +0100 (BST)

Yes, dump() does not dump the attributes of language objects of type LANGSXP. I don't know if that is deliberate or not, but in this case it would not be possible for dump to capture all the information, for note

> .. ..- attr(*, ".Environment")=<R_GlobalEnv>

and hence if you adopt Jim's suggestion, be aware that you will save() the whole of the workspace in order to capture the environment of the formula.

On Mon, 28 May 2007, jim holtman wrote:

> Don't know what it happening, but when I compared the output of 'str(tmp.aov)'
> before and after the 'source', I saw at least the following differences:
>
> before:
> $ terms :Classes 'terms', 'formula' length 3 y ~ a
> .. ..- attr(*, "variables")= language list(y, a)
> .. ..- attr(*, "factors")= int [1:2, 1] 0 1
> .. .. ..- attr(*, "dimnames")=List of 2
> .. .. .. ..$ : chr [1:2] "y" "a"
> .. .. .. ..$ : chr "a"
> .. ..- attr(*, "term.labels")= chr "a"
> .. ..- attr(*, "order")= int 1
> .. ..- attr(*, "intercept")= int 1
> .. ..- attr(*, "response")= int 1
> .. ..- attr(*, ".Environment")=<R_GlobalEnv>
> .. ..- attr(*, "predvars")= language list(y, a)
> .. ..- attr(*, "dataClasses")= Named chr [1:2] "numeric" "factor"
> .. .. ..- attr(*, "names")= chr [1:2] "y" "a"
>
> after:
> $ terms : language y ~ a
>
>
> So it would seem some of the attributes are not being saved.
>
> You might want to use 'save' instead. Here is the output:
>
>> tmp <- data.frame(y=rnorm(12), a=factor(rep(letters[1:4],3)))
>> tmp
> y a
> 1 0.61982575 a
> 2 -0.05612874 b
> 3 -0.15579551 c
> 4 -1.47075238 d
> 5 -0.47815006 a
> 6 0.41794156 b
> 7 1.35867955 c
> 8 -0.10278773 d
> 9 0.38767161 a
> 10 -0.05380504 b
> 11 -1.37705956 c
> 12 -0.41499456 d
>> tmp.aov <- aov(y ~ a, data=tmp)
>> summary(tmp.aov)
> Df Sum Sq Mean Sq F value Pr(>F)
> a 3 1.3068 0.4356 0.622 0.6204
> Residuals 8 5.6031 0.7004
>> save(tmp.aov, file="dumpdata.R")
>> rm(tmp.aov)
>> load("dumpdata.R")
>> ls()
>
>> summary(tmp.aov)
> Df Sum Sq Mean Sq F value Pr(>F)
> a 3 1.3068 0.4356 0.622 0.6204
> Residuals 8 5.6031 0.7004
>>
>
>
>
> On 5/28/07, Richard M. Heiberger <rmh_at_temple.edu> wrote:
>>
>>> tmp <- data.frame(y=rnorm(12), a=factor(rep(letters[1:4],3)))
>>> tmp
>> y a
>> 1 -0.60866099 a
>> 2 0.55500538 b
>> 3 0.12231693 c
>> 4 -0.24613790 d
>> 5 -0.09253593 a
>> 6 -1.54652581 b
>> 7 0.17204210 c
>> 8 -1.22778942 d
>> 9 1.22151194 a
>> 10 -0.43982577 b
>> 11 -1.25444287 c
>> 12 -0.97251060 d
>>> tmp.aov <- aov(y ~ a, data=tmp)
>>> summary(tmp.aov)
>> Df Sum Sq Mean Sq F value Pr(>F)
>> a 3 1.5220 0.5073 0.6973 0.5794
>> Residuals 8 5.8209 0.7276
>>> dump("tmp.aov")
>>> rm(tmp.aov)
>>> source("dumpdata.R")
>>> ls()
>> [1] "tmp" "tmp.aov"
>>> summary(tmp.aov)
>> Df Sum Sq Mean Sq F value Pr(>F)
>> NA 3 1.5220 0.5073 0.6973 0.5794
>> Residuals 8 5.8209 0.7276
>>>
>>
>>
>> The factor name in the summary() after dumping and sourcing the
>> aov object is missing.
>>
>>
>>> version
>> _
>> platform i386-pc-mingw32
>> arch i386
>> os mingw32
>> system i386, mingw32
>> status
>> major 2
>> minor 5.0
>> year 2007
>> month 04
>> day 23
>> svn rev 41293
>> language R
>> version.string R version 2.5.0 (2007-04-23)
>>>
>>
>> ______________________________________________
>> R-help_at_stat.math.ethz.ch 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.
>>
>
>
>
>

-- 
Brian D. Ripley,                  ripley_at_stats.ox.ac.uk
Professor of Applied Statistics,  http://www.stats.ox.ac.uk/~ripley/
University of Oxford,             Tel:  +44 1865 272861 (self)
1 South Parks Road,                     +44 1865 272866 (PA)
Oxford OX1 3TG, UK                Fax:  +44 1865 272595

______________________________________________
R-help_at_stat.math.ethz.ch 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.
Received on Tue 29 May 2007 - 06:05:46 GMT

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Tue 29 May 2007 - 06:31:15 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-help. Please read the posting guide before posting to the list.