Reputation: 11
credit$EDUCATION <- as.factor(ifelse(credit$EDUCATION == 1, 2, 3, 4, "Graduate_School", "College", "High_School", "Other", "Unknown"))
1 "Graduate_School", 2 "College", 3 "High_School", 4 "Other", Everything else that is not values 1 through 4 becomes Unknown
Upvotes: 1
Views: 49
Reputation: 887088
If we have numeric index, use that for replacement
credit$EDUCATION <- c("Graduate_School", "College", "High_School", "Other")[credit$EDUCATION]
credit$EDUCATION[is.na(credit$EDUCATION)] <- "Unknown"
Upvotes: 2