[Rd] No [[<-.factor()
William Dunlap
wdunlap at tibco.com
Thu Aug 26 02:31:27 CEST 2010
Should there be a [[<-.factor() that either throws
an error or acts like [<-.factor() to avoid making
an illegal object of class factor?
> z <- factor(c("Two","Two","Three"), levels=c("One","Two","Three"))
> z
[1] Two Two Three
Levels: One Two Three
> str(z)
Factor w/ 3 levels "One","Two","Three": 2 2 3
> z[[2]] <- "One"
> str(z) # the .Data part is now character
Factor w/ 3 levels "One","Two","Three": 2 One 3
> z
[1] <NA> <NA> <NA>
Levels: One Two Three
> z[2] <- "One"
Error in class(x) <- cx : adding class "factor" to an invalid object
Bill Dunlap
Spotfire, TIBCO Software
wdunlap tibco.com
More information about the R-devel
mailing list