The application here is grouping U.S. states into regions.
group1 <- c("ME", "NH", "VT", "MA", "CT", "RI")
group2 <- c("FL", "GA", "AL", "MS", "LA")
My data looks like:
SomeVar | State
---------------
300 | AL
331 | GA
103 | MA
500 | FL
And I would like to add a "region" column to the data according to the groupings above, like so:
SomeVar | State | Region
------------------------
300 | AL | 2
331 | GA | 2
103 | MA | 1
500 | FL | 2
Is there a straightforward way to assign factors based on groupings?