I have count data on utility disconnections in a set of about 100 zip codes. I also have data on the total number of utility customers in those zip codes. I merged the two together based on the year/month and zip code using:
new<- merge(disconnect_total,totalres, by=c("YR_MO","ZIP"))
Then I checked to see the column names and got the following:
head(new)
YR_MO ZIP TOTAL.x Non.CARE.x CARE.x FERA.x MBL.x TOTAL.y Non.CARE.y
1 201001 91901 15 12 3 0 0 6,516 5,675
2 201001 91902 11 9 2 0 0 6,275 5,616
3 201001 91905 1 1 0 0 0 769 595
4 201001 91906 3 2 1 0 0 1,298 929
5 201001 91910 42 22 20 0 0 25,645 17,180
6 201001 91911 51 21 30 0 0 23,843 13,518
CARE.y FERA.y MBL.y
1 825 16 146
2 642 17 110
3 174 0 23
4 361 8 37
5 8,268 197 400
6 10,032 293 429
In order to create a new variable for the percent of disconnections in each zip code in each year/month, I need to divide TOTAL.y (the total number of customers) by TOTAL.x (the total number of disconnections). I tried to do this and failed using:
percentdisconnect <- (new$TOTAL.x/new$TOTAL.y)
Can anyone help me?