[R] How to avoid ifelse statement converting factor to character

clint clint at ucsd.edu
Sat Nov 5 00:33:46 CET 2011


most all those posts were right in sourcing the problem....its just that
nobody actually offered a viable solution

the problem is that the new level "C" was not one of the original levels in
$social status

add "C" as a level and then just do the ol fashioned way and it works just
fine

do this:
data$SOCIAL_STATUS <- factor(data$SOCIAL_STATUS, levels =
c(levels(data$SOCIAL_STATUS), "C"))

then this:
data$SOCIAL_STATUS<-ifelse(data$SOCIAL_STATUS=="B" & data$MALE>4, "C", 
data$SOCIAL_STATUS)  

it is sooo much more helpful when someone who has addressed the specific
problem being asked replies instead of people just throwing random ideas out
there


--
View this message in context: http://r.789695.n4.nabble.com/How-to-avoid-ifelse-statement-converting-factor-to-character-tp895726p3992067.html
Sent from the R help mailing list archive at Nabble.com.



More information about the R-help mailing list