[R] Changing an unordered factor into an ordered factor

Mathew, Abraham T amathew at ku.edu
Thu Feb 4 00:36:40 CET 2010


 
I'm trying to change an unordered factor into an ordered factor:
 
data96$RV961327 <- data96$V961327
data96$RV961327[data96$V961327 %in% levels(data96$V961327)[4]] <- NA
data96$RV961327[data96$V961327 %in% levels(data96$V961327)[5]] <- NA
data96$RV961327 <- factor(data96$RV961327)
attributes(data96$RV961327)
levels(data96$RV961327)
data96$RV961327
 
data96$RRV961327 <- ordered(data96$RV961327, levels=c("Oppose", "Haven't thought much about this", "Favor"))
attributes(data96$RRV961327)
levels(data96$RRV961327)
data96$RRV961327
cbind(data96$V961327, data96$RV961327, data96$RRV961327)
table(data96$V961327, data96$RV961327)
table(data96$V961327, data96$RRV961327)
 
The first block of code works.
 
However, when I run the ordered command, it only turns all the values into NA's. According to attributes, however, they have been transfered into an ordered factor....but still show up as NA's.
 
 
Help



More information about the R-help mailing list