[R] levels() deletes other attributes

From: Heinz Tuechler <tuechler_at_gmx.at>
Date: Tue 19 Jul 2005 - 00:25:14 EST


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?

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 Received on Tue Jul 19 00:28:06 2005

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