setwd("~/Desktop")
data <- read.csv("lgas.csv")
hf<- read.csv("sample_health_facilities.csv")
First, I grabbed all of the southern areas using grep()
as well as the pop_2006 variable from the other data set. Then I merged both of these new data frames by the id lga_id.
south.data <- hf[grep("South", hf$zone),]
pop_2006 <- data[,c(1,3)]
nd <- merge(south.data, pop_2006, by = "lga_id")
To answer the questions regarding the number of full time doctors and nurses I aggregated by state.
aggregate(num_doctors_fulltime~ state, data = nd, sum)
## state num_doctors_fulltime
## 1 Abia 308
## 2 Anambra 3
## 3 Cross River 0
## 4 Delta 2
## 5 Edo 0
## 6 Ekiti 1
## 7 Imo 0
## 8 Lagos 4
## 9 Ogun 2
## 10 Osun 1
## 11 Rivers 2
aggregate(num_nurses_fulltime ~ state, data = nd, sum)
## state num_nurses_fulltime
## 1 Anambra 4
## 2 Cross River 3
## 3 Delta 10
## 4 Edo 0
## 5 Ekiti 2
## 6 Imo 8
## 7 Lagos 4
## 8 Ogun 0
## 9 Osun 6
## 10 Rivers 2
Finally, I ordered the dataset by population after aggregating by state.
bystate <- aggregate(pop_2006 ~ state, data = nd, sum)
final <- merge(nd, bystate, by = "state")
names(final)[names(final)=="pop_2006.y"] <- "statepop"
final.sort <- final[order(-final$statepop),]
aggregate(num_doctors_fulltime ~ state,data = nd, sum)
## state num_doctors_fulltime
## 1 Abia 308
## 2 Anambra 3
## 3 Cross River 0
## 4 Delta 2
## 5 Edo 0
## 6 Ekiti 1
## 7 Imo 0
## 8 Lagos 4
## 9 Ogun 2
## 10 Osun 1
## 11 Rivers 2
aggregate(num_nurses_fulltime ~ state,data = nd, sum)
## state num_nurses_fulltime
## 1 Anambra 4
## 2 Cross River 3
## 3 Delta 10
## 4 Edo 0
## 5 Ekiti 2
## 6 Imo 8
## 7 Lagos 4
## 8 Ogun 0
## 9 Osun 6
## 10 Rivers 2
This is an R Markdown document. Markdown is a simple formatting syntax for authoring web pages (click the MD toolbar button for help on Markdown).