I would like to create a column called "Region" based on values of "Community area", eg Community area of 1 =North, community area of 2=South. I want it to be like this:
Community area Region
25 West
67 Southwest
39 South
40 South
25 West
I tried the following code but it is not helpful:
region<-function(x){if(x==c(8,32,33)){crime$Region<-"Central"}
else if(x==c(5,6,7,21,22)){crime$Region<-"North"}
else if(x==c(1:4,9:14,76,77)){crime$Region<-"Far North Side"}
else if(x==c(15:20)){crime$Region<-"Northwest Side"}
else if(x==c(23:31)){crime$Region<-"West"}
else if(x==c(34:43,60,69)){crime$Region<-"South"}
else if(x==c(56:59,61:68)){crime$Region<-"Southwest Side"}
else if(x==c(44:55)){crime$Region<-"Far Southeast Side"}
else if(x==c(70:75)){crime$Region<-"Far Southwest Side"}
else {crime$Region<-"Other"}
}
region(crime$Community.Area)