Hi all, I have a dataframe of users which contain US-state codes. Now I want to add a column named REGION based on the state code. I have already done a mapping:
NorthEast <- c(07, 20, 22, 30, 31, 33, 39, 41, 47) MidWest <- c(14, 15, 16, 17, 23, 24, 26, 28, 35, 36, 43, 52) South <- c(01, 04, 08, 09, 10, 11, 18, 19, 21, 25, 34, 37, 42, 44, 45, 49, 51) West <- c(02, 03, 05, 06, 12, 13, 27, 29, 32, 38, 46, 50, 53) Other <- c(40, 48, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 65, 66, 94, 98, 99) So for example: Name State_Code Tom 20 Harry 56 Ben 05 Sally 04 Should become like: So for example: Name State_Code REGION Tom 20 NorthEast Harry 56 Other Ben 05 West Sally 04 South Could anyone help me with a clever statement? -- View this message in context: http://r.789695.n4.nabble.com/Add-column-to-dataframe-based-on-code-in-other-column-tp4673335.html Sent from the R help mailing list archive at Nabble.com. ______________________________________________ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.