library("dplyr")
## 
## Attaching package: 'dplyr'
## 
## The following object is masked from 'package:stats':
## 
##     filter
## 
## The following objects are masked from 'package:base':
## 
##     intersect, setdiff, setequal, union
setwd("/Users/knarf/Copy/github/qmssviz/lab1")
lgas <- read.csv("lgas.csv")
shf <- read.csv("sample_health_facilities.csv")
str(lgas)
## 'data.frame':    774 obs. of  13 variables:
##  $ lga_id             : int  1 2 3 4 5 6 7 8 9 10 ...
##  $ unique_lga         : Factor w/ 773 levels "abia_aba_north",..: 142 275 39 211 1 2 563 564 169 292 ...
##  $ pop_2006           : int  100180 58444 139090 151723 107488 423852 201329 250278 144802 195652 ...
##  $ lga                : Factor w/ 768 levels "Aba North","Aba South",..: 3 4 5 6 1 2 7 8 9 10 ...
##  $ state              : Factor w/ 37 levels "Abia","Adamawa",..: 8 15 3 11 1 1 28 28 9 17 ...
##  $ zone               : Factor w/ 6 levels "North-Central",..: 2 1 4 5 5 5 6 6 4 5 ...
##  $ area_sq_km         : num  3967.1 992.4 190 584.1 22.8 ...
##  $ surveying_effort   : Factor w/ 4 levels "113","148","Others",..: 3 1 3 3 3 3 3 3 3 3 ...
##  $ pop_density_2006   : num  25.3 58.9 732.1 259.8 4719.5 ...
##  $ longitude          : num  13.33 6.85 7.77 8.22 7.37 ...
##  $ latitude           : num  13.43 8.88 5.02 6.26 5.11 ...
##  $ senatorial_district: Factor w/ 67 levels "","Abia Central",..: 40 1 33 21 4 4 42 42 12 53 ...
##  $ TA_names           : Factor w/ 121 levels "Abdul Samad Isah Haruna",..: 75 57 62 83 19 114 108 108 94 80 ...
str(shf)
## 'data.frame':    50 obs. of  10 variables:
##  $ lga                   : Factor w/ 50 levels "Aliero","Anaocha",..: 6 2 7 38 17 4 16 26 8 18 ...
##  $ lga_id                : int  91 49 96 611 258 76 232 441 101 261 ...
##  $ state                 : Factor w/ 24 levels "Abia","Adamawa",..: 21 3 14 10 5 3 4 17 6 18 ...
##  $ zone                  : Factor w/ 6 levels "North-Central",..: 1 5 3 5 1 5 2 6 4 1 ...
##  $ c_section_yn          : logi  FALSE FALSE FALSE FALSE FALSE FALSE ...
##  $ num_nurses_fulltime   : int  0 2 1 0 0 0 0 1 3 0 ...
##  $ gps                   : Factor w/ 50 levels "10.50716994 7.39845258 633.4000244140625 5.0",..: 48 27 14 24 42 30 7 33 34 47 ...
##  $ num_lab_techs_fulltime: int  1 NA 1 0 0 1 0 0 2 0 ...
##  $ management            : Factor w/ 1 level "public": 1 1 1 1 1 1 1 NA 1 1 ...
##  $ num_doctors_fulltime  : int  0 NA 0 0 0 1 0 1 0 0 ...
shf_south <- shf[shf$zone == "South-South", ]
merge <- merge(shf_south, lgas, by.x = "lga_id", by.y = "lga_id")
sum(merge$num_nurses_fulltime)
## [1] 15
sum(merge$num_doctors_fulltime)
## [1] 4
merge_ordered <- merge[order(-merge$pop_density_2006), ]
head(merge_ordered)
##   lga_id             lga.x     state.x      zone.x c_section_yn
## 9    746       Warri South       Delta South-South        FALSE
## 2    324         Ika South       Delta South-South        FALSE
## 1    101           Bekwara Cross River South-South        FALSE
## 5    562 Ogba/Egbema/Ndoni      Rivers South-South        FALSE
## 7    720     Ughelli South       Delta South-South        FALSE
## 3    523       Ndokwa-West       Delta South-South         TRUE
##   num_nurses_fulltime                                            gps
## 9                   0    5.5714229 5.70460127 38.400001525878906 5.0
## 2                   1  6.247004270553589 6.134732365608215 178.0 4.0
## 1                   3 6.6513848304748535 8.869051337242126 151.0 4.0
## 5                   2   5.36041084 6.67822917 30.399999618530273 5.0
## 7                   1   5.37297057 5.91941726 25.200000762939453 5.0
## 3                   8   5.70480295 6.43165459 34.099998474121094 5.0
##   num_lab_techs_fulltime management num_doctors_fulltime
## 9                      0     public                    0
## 2                      0     public                    0
## 1                      2     public                    0
## 5                      0       <NA>                    2
## 7                      0     public                    0
## 3                      1       <NA>                    2
##                 unique_lga pop_2006             lga.y     state.y
## 9        delta_warri_south   303417       Warri South       Delta
## 2          delta_ika_south   162594         Ika South       Delta
## 1      cross_river_bekwara   105822           Bekwara Cross River
## 5 rivers_ogba_egbema_ndoni   284010 Ogba/Egbema/Ndoni      Rivers
## 7      delta_ughelli_south   213576     Ughelli South       Delta
## 3        delta_ndokwa_west   149325       Ndokwa-West       Delta
##        zone.y area_sq_km surveying_effort pop_density_2006 longitude
## 9 South-South   633.7680           Others         478.7509  5.610246
## 2 South-South   435.8570           Others         373.0444  6.199869
## 1 South-South   305.5696           Others         346.3106  8.909722
## 5 South-South   969.7606           Others         292.8661  6.636043
## 7 South-South   786.2732           Others         271.6308  5.901492
## 3 South-South   816.4446           Others         182.8967  6.341288
##   latitude senatorial_district                     TA_names
## 9 5.628901         Delta South                Dennis Bennis
## 2 6.182437         Delta North             Ayuya Tega David
## 1 6.698031   Cross-River North       Patrick  Theresa Ogeyi
## 5 5.398500         Rivers West Amakiri Fikiniseleka Collins
## 7 5.343676       Delta Central                Dennis Bennis
## 3 5.801389         Delta North        Ogbolu Chidi McDonald
# done