Re: [R] levels() deletes other attributes

From: Heinz Tuechler <tuechler_at_gmx.at>
Date: Tue 19 Jul 2005 - 01:10:30 EST


At 16:53 18.07.2005 +0200, Heinz Tuechler wrote:
>At 09:29 18.07.2005 -0500, Frank E Harrell Jr wrote:
>>Heinz Tuechler wrote:
>>> Dear All,
>>>
>>> it seems to me that levels() deletes other attributes. See the following
>>> example:
>>>
>>> ## example with levels
>>> f1 <- factor(c('level c','level b','level a','level c'), ordered=TRUE)
>>> attr(f1, 'testattribute') <- 'teststring'
>>> attributes(f1)
>>> levels(f1) <- c('L-A', 'L-B', 'L-C')
>>> attributes(f1)
>>>
>>> If I run it, after assigning new levels, the class is only "factor"
instead
>>> of "ordered" "factor" and the $testattribute "teststring" is gone.
>>>
>>> The same happens to the label() attribute of Hmisc.
>>>
>>> ## example with levels and label
>>> library(Hmisc)
>>> f1 <- factor(c('level c','level b','level a','level c'), ordered=TRUE)
>>> label(f1) <- 'factor f1'
>>> attr(f1, 'testattribute') <- 'teststring'
>>> attributes(f1)
>>> levels(f1) <- c('L-A', 'L-B', 'L-C')
>>> attributes(f1)
>>>
>>> Should I expect this behaviour?
>>
>>Does the same thing happen when you do
>>
>> attr(f1,'levels') <- c('L-A',...)
>>
>>Frank
>
>No, it does not. With attr(f1,'levels') <- c('L-A', 'L-B', 'L-C') only the
>levels are changed, all other attributes remain as before.
>Heinz
>
I think, I know why attr(f1,'levels') behaves different from levels(f1) <- . As far as I see, the method of levels for factor does not use attr() but factor().
Heinz
>>>
>>> Thanks
>>>
>>> Heinz
>>>
>>> # R-Version 2.1.0 Patched (2005-05-30)
>>> # Windows98
>>>
>>> ______________________________________________
>>> R-help@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
>>>
>>
>>
>>--
>>Frank E Harrell Jr Professor and Chair School of Medicine
>> Department of Biostatistics Vanderbilt University
>>
>>
>
>______________________________________________
>R-help@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
>
>



R-help@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 Received on Tue Jul 19 01:12:19 2005

This archive was generated by hypermail 2.1.8 : Fri 03 Mar 2006 - 03:33:46 EST