# R data frame create a new variable which corresponds to one of the existing one

Currently this is what I get. "community_area_clean" is the new variable that I added by extracting a variable that lists all the communities from a data frame. "CommArea_Name" is the original "unclean" variable. But I find that the names in "community_area_clean" do not correspond to the names in "CommArea_Name". How can I fix it? Thanks.

• Does that CommArea_Num column mean anything? It looks like LINCOLN SQUARE has a 4 there and is the fourth in the community_area_clean column. Same for ROGERS PARK, which has a 1 and is first in the other column. Is that true all the way through? Does the AREA_KM correspond to the CommArea_Name place or the community_area_clean place in each row/ – Spacedman Jan 10 '17 at 16:57

If my assumptions about CommArea_Num are correct, then:
data$community_area_clean = data$community_area_clean[data\$CommAreaNum]

should remap that column. Note that the AREA_KM fields will remain in the order currently shown.
• Do the same thing with AREA_KM instead. Note you should end up with the area of ROGERS PARK as 2.700750 units. If this is actually the area of KENWOOD then some more fiddling required... – Spacedman Jan 10 '17 at 18:20