Import the data

DT <- read.csv("cema_internship_task_2023.csv")
head(DT,5)
  period                 county Total.Dewormed Acute.Malnutrition
1 Jan-23         Baringo County           3659                  8
2 Jan-23           Bomet County           1580                 NA
3 Jan-23         Bungoma County           6590                 24
4 Jan-23           Busia County           7564                 NA
5 Jan-23 Elgeyo Marakwet County           1407                 NA
  stunted.6.23.months stunted.0..6.months stunted.24.59.months diarrhoea.cases
1                 471                  34                  380            2620
2                   1                   3                   NA            1984
3                  98                 154                   23            4576
4                 396                 143                  111            2239
5                  92                  71                    5            2739
  Underweight.0..6.months Underweight.6.23.months Underweight.24.59.Months
1                      85                     739                      731
2                      41                      86                       16
3                     231                     315                      120
4                     251                     608                      125
5                      57                     104                       21
attach(DT)

Check the number of observations

library(dplyr)
count(DT)
     n
1 1410

Create summary statistics

Total Dewormed

library(tidyverse)
library(ggpubr)
library(rstatix)

SUMM <- DT %>%
  group_by(county) %>%
  get_summary_stats(Total.Dewormed, type = "mean_sd")
SUMM
# A tibble: 47 × 5
   county                 variable           n   mean     sd
   <chr>                  <fct>          <dbl>  <dbl>  <dbl>
 1 Baringo County         Total.Dewormed    30 10597. 12659.
 2 Bomet County           Total.Dewormed    30  1656.   806.
 3 Bungoma County         Total.Dewormed    30 14638. 25747.
 4 Busia County           Total.Dewormed    30  4379.  1668.
 5 Elgeyo Marakwet County Total.Dewormed    30  6774. 11168.
 6 Embu County            Total.Dewormed    30  8960. 13764.
 7 Garissa County         Total.Dewormed    30 10685.  7267.
 8 Homa Bay County        Total.Dewormed    30  7666. 16756.
 9 Isiolo County          Total.Dewormed    30  3425.  6157.
10 Kajiado County         Total.Dewormed    30 16991. 32105.
# ℹ 37 more rows

Acute Mulnutrition

SUMM2 <- DT %>%
  group_by(county) %>%
  get_summary_stats(Acute.Malnutrition, type = "mean_sd")
SUMM2
# A tibble: 44 × 5
   county          variable               n   mean     sd
   <chr>           <fct>              <dbl>  <dbl>  <dbl>
 1 Baringo County  Acute.Malnutrition    28   8.82  10.1 
 2 Bomet County    Acute.Malnutrition     6   1.83   1.17
 3 Bungoma County  Acute.Malnutrition    13  10.2    9.94
 4 Busia County    Acute.Malnutrition    15   5.8    6.7 
 5 Embu County     Acute.Malnutrition    29  42.6   25.0 
 6 Garissa County  Acute.Malnutrition    30 269.   224.  
 7 Homa Bay County Acute.Malnutrition    30  26.0   22.9 
 8 Isiolo County   Acute.Malnutrition    30  64.4   50.4 
 9 Kajiado County  Acute.Malnutrition    30  78.4   59.0 
10 Kakamega County Acute.Malnutrition    26  24.2   15.7 
# ℹ 34 more rows

Stunted.6.23.months

SUMM3 <- DT %>%
  group_by(county) %>%
  get_summary_stats(stunted.6.23.months, type = "mean_sd")
SUMM3
# A tibble: 47 × 5
   county                 variable                n  mean    sd
   <chr>                  <fct>               <dbl> <dbl> <dbl>
 1 Baringo County         stunted.6.23.months    30 262.  185. 
 2 Bomet County           stunted.6.23.months    21  30.0  81.7
 3 Bungoma County         stunted.6.23.months    30 121.   69.7
 4 Busia County           stunted.6.23.months    30 339.  144. 
 5 Elgeyo Marakwet County stunted.6.23.months    30  80.0  48.6
 6 Embu County            stunted.6.23.months    30 264.  113. 
 7 Garissa County         stunted.6.23.months    30  40.6  44.5
 8 Homa Bay County        stunted.6.23.months    30 144.   67.9
 9 Isiolo County          stunted.6.23.months    30  59.2  46.2
10 Kajiado County         stunted.6.23.months    30 275.  148. 
# ℹ 37 more rows

View the whole summaries across counties

View(SUMM3)

Additional Command to View Summary Statistics Per counties

library(dplyr)
SUMM4<- group_by(DT, county) %>%
  summarise(
    count = n(),
    mean = mean(stunted.0..6.months, na.rm = TRUE),
    sd = sd(stunted.0..6.months, na.rm = TRUE),
    median = median(stunted.0..6.months, na.rm = TRUE),
    max = max(stunted.0..6.months, na.rm = TRUE),
    min = min(stunted.0..6.months, na.rm = TRUE),
    IQR = IQR(stunted.0..6.months, na.rm = TRUE)
  )
SUMM4
# A tibble: 47 × 8
   county                 count   mean     sd median   max   min   IQR
   <chr>                  <int>  <dbl>  <dbl>  <dbl> <int> <int> <dbl>
 1 Baringo County            30 122.   119.     75.5   555    34  76.8
 2 Bomet County              30   5.52   5.44    3      22     1   5  
 3 Bungoma County            30  95.3   76.2    82     404    32  37.8
 4 Busia County              30 173.   145.    146.    883    53  77  
 5 Elgeyo Marakwet County    30  68.4   34.7    60.5   169     6  28.2
 6 Embu County               30  94.1   55.9    90     348     4  35.5
 7 Garissa County            30  25.7   44.7     9.5   208     1  12.8
 8 Homa Bay County           30 120.    66.2   106.    378    44  70  
 9 Isiolo County             30  27.4   45.6    10     207     1  16  
10 Kajiado County            30 167.   121.    108     484    51 151  
# ℹ 37 more rows

View the whole Summaries

View(SUMM4)

View the results using KableExtra Library

library(kableExtra)
kable(SUMM4)
county count mean sd median max min IQR
Baringo County 30 121.500000 119.124030 75.5 555 34 76.75
Bomet County 30 5.523809 5.437086 3.0 22 1 5.00
Bungoma County 30 95.266667 76.179431 82.0 404 32 37.75
Busia County 30 173.300000 145.228037 146.5 883 53 77.00
Elgeyo Marakwet County 30 68.433333 34.712299 60.5 169 6 28.25
Embu County 30 94.100000 55.929358 90.0 348 4 35.50
Garissa County 30 25.678571 44.724716 9.5 208 1 12.75
Homa Bay County 30 120.033333 66.228176 105.5 378 44 70.00
Isiolo County 30 27.379310 45.602642 10.0 207 1 16.00
Kajiado County 30 167.233333 120.566102 108.0 484 51 151.00
Kakamega County 30 220.433333 186.034235 161.5 787 33 169.25
Kericho County 30 33.142857 33.917890 23.0 134 1 32.00
Kiambu County 30 373.900000 136.202524 346.5 826 83 95.25
Kilifi County 30 328.633333 91.684799 335.0 558 145 117.25
Kirinyaga County 30 62.533333 46.506012 49.0 218 17 47.75
Kisii County 30 87.300000 100.394446 43.0 468 4 86.25
Kisumu County 30 96.200000 134.511735 68.0 784 6 46.00
Kitui County 30 175.000000 77.404446 176.5 431 35 61.00
Kwale County 30 135.000000 43.401891 124.5 245 31 44.50
Laikipia County 30 231.100000 235.376492 193.0 1457 90 57.50
Lamu County 30 10.148148 6.746530 9.0 31 2 5.00
Machakos County 30 43.166667 54.303796 23.0 287 2 45.50
Makueni County 30 106.266667 42.458039 101.5 274 48 42.00
Mandera County 30 85.633333 76.928755 77.5 445 12 59.75
Marsabit County 30 37.100000 22.884041 31.0 91 9 34.00
Meru County 30 124.000000 54.097613 117.5 295 42 46.25
Migori County 30 64.433333 54.254625 46.5 252 8 31.00
Mombasa County 30 156.566667 104.893602 137.0 615 58 78.00
Muranga County 30 265.166667 76.785453 250.0 463 140 97.25
Nairobi County 30 1228.533333 1342.443519 829.0 7900 513 463.75
Nakuru County 30 280.700000 73.649285 269.0 409 141 85.25
Nandi County 30 74.933333 43.759478 62.5 219 19 41.50
Narok County 30 85.533333 71.996999 52.5 265 17 89.00
Nyamira County 30 46.733333 23.752943 40.5 119 11 33.25
Nyandarua County 30 96.500000 53.274662 82.5 351 43 35.00
Nyeri County 30 178.600000 40.937800 169.0 284 104 51.25
Samburu County 30 35.333333 29.605840 26.0 122 1 31.25
Siaya County 30 25.066667 32.316253 10.0 146 2 23.00
Taita Taveta County 30 89.466667 44.575185 84.5 202 4 55.50
Tana River County 30 41.166667 107.404836 14.5 601 3 19.25
Tharaka Nithi County 30 88.433333 21.993233 95.0 121 28 29.50
Trans Nzoia County 30 130.966667 51.412787 127.5 307 9 54.50
Turkana County 30 239.466667 148.509081 200.0 558 65 246.25
Uasin Gishu County 30 191.633333 209.973969 128.0 849 45 64.50
Vihiga County 30 59.700000 50.087613 45.5 256 9 24.75
Wajir County 30 26.107143 44.588937 9.5 198 1 21.50
West Pokot County 30 37.866667 35.805734 27.5 143 4 41.25