[datatable-help] Replacing NA values for a categorical variable results in numerical replacements

affableambler nfields at gmail.com
Thu Nov 24 03:23:18 CET 2016


This may not be the most elegant solution, but one way to do it would be to
convert the factor to a character vector, replace the NAs, and then convert
it back to a factor:

Prestige.bc<-Prestige
Prestige.bc$type<-as.character(Prestige.bc$type)
Prestige.bc$type[which(is.na(Prestige.bc$type))]<-'bc'
Prestige.bc$type<-as.factor(Prestige.bc$type)




--
View this message in context: http://r.789695.n4.nabble.com/Replacing-NA-values-for-a-categorical-variable-results-in-numerical-replacements-tp4726789p4726790.html
Sent from the datatable-help mailing list archive at Nabble.com.


More information about the datatable-help mailing list