How do I create a new column of character values based on numeric value that are to be assigned the following names: 0 = user, 1 = admin, 2 = sponsor
dat1 one two three 1 Bob 0 2 Mary 0 3 restaurant 2 4 company 1 so based on those names, how do I get to this:
dat1 one two three 1 Bob 0 user 2 Mary 0 user 3 restaurant 2 sponsor 4 company 1 admin dat1 <- data.frame(one=c("Bob", "Mary", "restaurant", "company"), two=c("0","0", "2", "1")) And yes I know how simply create them via:
dat1 <- data.frame(one=c("Bob", "Mary", "restaurant", "company"), two=c("0","0", "2", "1"), three=c("user", "user", "sponsor", "admin")) But what's the function that would preform the task? So under column three, based on the corresponding row under column two, I want 0 = user, 1 = admin, 2 = sponsor.