Hello,
Iβm trying to count total cases by city. My grouping code worked but my summarise code did not. Can anyone see my error(s)? Reprex below.
Thank you, Alicia
pacman::p_load(
rio, # for importing data
here, # for locating files
skimr, # for reviewing the data
janitor, # for data cleaning
epikit, # creating age categories
gtsummary, # creating tables
apyramid, # for age/sex pyramids
RColorBrewer, # for colour palettes
viridis, # for color blind friendly color scales
scales, # percents in tables
flextable, # for making pretty tables
gghighlight, # highlighting plot parts
ggExtra, # special plotting functions
tsibble, # for epiweeks and other time series analyses
lubridate, # for dates
datapasta,
reprex,
tidyverse # for data management and visualization
)
demo β data.frame(
stringsAsFactors = FALSE,
pid = c(β9174d755abce7fb7β,
β469fd41756126126β,β9fb6d7c3a1be6987β,β6b2c6f9d5980edb8β,
β4c3ebec8e4794beeβ,β4c3ebec8e4794beeβ,β53cce1871a2312a3β,
β2b6134374e2562cfβ,β2b6134374e2562cfβ,βdc1f54eccf6a0588β),
city = c(βAtlantaβ,βUnion Cityβ,
βAtlantaβ,βAtlantaβ,βAtlantaβ,βEast Pointβ,βAlpharettaβ,
βAtlantaβ,βEast Pointβ,βAlpharettaβ),
gender = c(βMaleβ,βFemaleβ,βFemaleβ,
βMaleβ,βFemaleβ,βFemaleβ,βMaleβ,βFemaleβ,βFemaleβ,
βFemaleβ)
)
try to get total cases by city
demo %>%
group_by(city) %>%
summarise(total_cases = count(pid))
#> Error in summarise()
:
#> In argument: total_cases = count(pid)
.
#> In group 1: city = "Alpharetta"
.
#> Caused by error in UseMethod()
:
#> ! no applicable method for βcountβ applied to an object of class βcharacterβ
<sup>Created on 2024-03-06 with [reprex v2.1.0](https://reprex.tidyverse.org)</sup>
<details style="margin-bottom:10px;">
<summary>
Session info
</summary>
``` r
sessionInfo()
#> R version 4.3.2 (2023-10-31 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/Denver
#> 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 tidyverse_2.0.0
#> [9] reprex_2.1.0 datapasta_3.1.0 lubridate_1.9.3 tsibble_1.1.4
#> [13] ggExtra_0.10.1 gghighlight_0.4.1 ggplot2_3.4.4 flextable_0.9.4
#> [17] scales_1.3.0 viridis_0.6.5 viridisLite_0.4.2 RColorBrewer_1.1-3
#> [21] apyramid_0.1.3 gtsummary_1.7.2 epikit_0.1.6 janitor_2.2.0
#> [25] skimr_2.1.5 here_1.0.1 rio_1.0.1
#>
#> loaded via a namespace (and not attached):
#> [1] DBI_1.2.1 gridExtra_2.3 rlang_1.1.3
#> [4] magrittr_2.0.3 snakecase_0.11.1 e1071_1.7-14
#> [7] compiler_4.3.2 systemfonts_1.0.5 vctrs_0.6.5
#> [10] httpcode_0.3.0 pkgconfig_2.0.3 crayon_1.5.2
#> [13] fastmap_1.1.1 ellipsis_0.3.2 utf8_1.2.4
#> [16] promises_1.2.1 rmarkdown_2.25 tzdb_0.4.0
#> [19] anytime_0.3.9 ragg_1.2.7 xfun_0.41
#> [22] jsonlite_1.8.8 later_1.3.2 uuid_1.2-0
#> [25] R6_2.5.1 stringi_1.8.3 Rcpp_1.0.12
#> [28] knitr_1.45 base64enc_0.1-3 pacman_0.5.1
#> [31] httpuv_1.6.14 timechange_0.3.0 tidyselect_1.2.0
#> [34] rstudioapi_0.15.0 yaml_2.3.8 miniUI_0.1.1.1
#> [37] curl_5.2.0 shiny_1.8.0 withr_3.0.0
#> [40] askpass_1.2.0 evaluate_0.23 sf_1.0-15
#> [43] units_0.8-5 proxy_0.4-27 zip_2.3.1
#> [46] xml2_1.3.6 pillar_1.9.0 KernSmooth_2.23-22
#> [49] generics_0.1.3 rprojroot_2.0.4 hms_1.1.3
#> [52] munsell_0.5.0 xtable_1.8-4 class_7.3-22
#> [55] glue_1.7.0 gdtools_0.3.5 tools_4.3.2
#> [58] gfonts_0.2.0 data.table_1.15.0 fs_1.6.3
#> [61] grid_4.3.2 colorspace_2.1-0 repr_1.1.6
#> [64] cli_3.6.2 textshaping_0.3.7 officer_0.6.3
#> [67] fontBitstreamVera_0.1.1 fansi_1.0.6 broom.helpers_1.14.0
#> [70] gt_0.10.1 gtable_0.3.4 digest_0.6.34
#> [73] fontquiver_0.2.1 classInt_0.4-10 crul_1.4.0
#> [76] htmltools_0.5.7 lifecycle_1.0.4 mime_0.12
#> [79] fontLiberation_0.1.0 openssl_2.1.1