Displaying 1 result from an estimated 1 matches for "alllevels".
2010 Apr 01
1
Sharing levels across multiple factor vectors
...uch less space that I could actually
understand the screen display. Converting a single factor column to
integers is easy: You can just use as.numeric(). But sharing the labels
across two vectors has eluded me.
Here's what I tried: First, collect all the levels into a single vector:
> allLevels <- unique( c( levels( df$a ), levels( df$b ) ) )
> allLevels
[1] "alice" "bob" "kenny"
Now change the "levels" attribute of each vector:
> for (c in colnames(df)) levels( df[,c] ) <- allLevels
> data.frame (
+ as.numeric( a ),
+ as...