# This is an example of de novo construction of a colored factor
weekdays <- colored(c("Mon","Tue","Wed","Thu","Fri"),
color.key=c(Mon="blue",Tue="red",Wed="yellow",
Thu="purple", Fri="green"))
# This demonstrates how one might use the 'colored' constructor
# to expand the level set of an existing factor.
week <- colored(weekdays,
color.key=c(Sun="white", key(weekdays), Sat="gray"),
ordered=TRUE)
# Note that 'droplevels.factor' works fine on colored factors
levels(week)
levels(droplevels(week))
Run the code above in your browser using DataLab