Note: This is a demonstration of a code challenge as part of the Intro to R course.
Hi Community,
I’ve retrieved public EMS calls into the ‘demo_data’ data frame below, and used the helpful forum on Applied Epi to create a frequency table by Call Type and Date. Now I’m a bit stuck, because I’m not sure what the most efficient and intuitive next step for learning which Call Type and Date (combined) had the highest frequency of EMS calls (assume the demo data represents a much, much larger dataset that will be harder to parse by visualization alone).
I’m wondering if you have advice? Is this an answer I can pull from a frequency table, or should I take a different approach to analyzing the data frame instead?
Thank you for the support!
Rachel
pacman::p_load(rio, lubridate, datapasta, reprex, tidyverse)
demo_data<- data.frame(
stringsAsFactors = FALSE,
CallNumber = c(241560871L,
241560939L,241562505L,
241570146L,241563077L,
241563031L,241560981L,
241563229L,241563178L,
241563511L),
Date = c("2024-06-04",
"2024-06-04","2024-06-04",
"2024-06-05",
"2024-06-04","2024-06-04",
"2024-06-04","2024-06-04",
"2024-06-04","2024-06-04"),
Type = c("Medical Incident","Alarms",
"Medical Incident",
"Medical Incident","Medical Incident",
"Medical Incident",
"Citizen Assist / Service Call",
"Medical Incident",
"Medical Incident",
"Medical Incident"))
#frequency by date
table <- demo_data %>%
group_by(Type, Date) %>%
summarise(
total_calls = n())
#> `summarise()` has grouped output by 'Type'. You can override using the
#> `.groups` argument.
#frequency by date and Call type
table<-demo_data %>%
group_by(Type, Date) %>%
summarise(count = n(), .groups = "drop") %>%
pivot_wider(names_from = Type, values_from = count)
Created on 2024-08-06 with reprex v2.1.0
Session info
sessionInfo()
#> R version 4.3.3 (2024-02-29 ucrt)
#> Platform: x86_64-w64-mingw32/x64 (64-bit)
#> Running under: Windows 10 x64 (build 19043)
#>
#> Matrix products: default
#>
#>
#> locale:
#> [1] LC_COLLATE=English_United States.utf8
#> [2] LC_CTYPE=English_United States.utf8
#> [3] LC_MONETARY=English_United States.utf8
#> [4] LC_NUMERIC=C
#> [5] LC_TIME=English_United States.utf8
#>
#> time zone: America/Los_Angeles
#> tzcode source: internal
#>
#> attached base packages:
#> [1] stats graphics grDevices utils datasets methods base
#>
#> other attached packages:
#> [1] forcats_1.0.0 stringr_1.5.1 dplyr_1.1.4 purrr_1.0.2
#> [5] readr_2.1.5 tidyr_1.3.1 tibble_3.2.1 ggplot2_3.5.1
#> [9] tidyverse_2.0.0 reprex_2.1.0 datapasta_3.1.0 lubridate_1.9.3
#> [13] rio_1.0.1
#>
#> loaded via a namespace (and not attached):
#> [1] gtable_0.3.5 compiler_4.3.3 tidyselect_1.2.1 scales_1.3.0
#> [5] yaml_2.3.8 fastmap_1.1.1 R6_2.5.1 generics_0.1.3
#> [9] knitr_1.46 munsell_0.5.1 tzdb_0.4.0 pillar_1.9.0
#> [13] rlang_1.1.3 utf8_1.2.4 stringi_1.8.3 xfun_0.43
#> [17] fs_1.6.4 timechange_0.3.0 cli_3.6.2 withr_3.0.0
#> [21] magrittr_2.0.3 digest_0.6.35 grid_4.3.3 rstudioapi_0.16.0
#> [25] hms_1.1.3 lifecycle_1.0.4 vctrs_0.6.5 evaluate_0.23
#> [29] glue_1.7.0 fansi_1.0.6 colorspace_2.1-0 pacman_0.5.1
#> [33] rmarkdown_2.26 tools_4.3.3 pkgconfig_2.0.3 htmltools_0.5.8.1