Helper function to count cancer cases in the FCDS data by year and age group,
in addition to any groups already present in the data. For convenience, you
may additionally filter to include particular values of sex, race, year,
county name and hispanic ethnicity. See fcds_const()
for more information
about possible values for these variables. By default, count_fcds()
ensures
that age_group
, year_group
, and year
are included in the grouping
variables if they are present in the data. If they are not, or if they are
not present in the FCDS data, then it would be better to use dplyr::count()
directly.
count_fcds(data, ..., sex = NULL, race = NULL, origin = NULL, county_name = NULL, default_groups = c("year_group", "year", "age_group"), discard_unseen_levels = TRUE, moffitt_catchment = FALSE)
data | A data frame |
---|---|
... | Unquoted column names to be added to the grouping of the output and subsequent counting. |
sex | Character vector of values of |
race | Character vector of values of |
origin | Character vector of values of |
county_name | Character vector of values of |
default_groups | Variables that should be included in the grouping,
prior to counting cancer cases. Set to |
discard_unseen_levels | If |
moffitt_catchment | Deprecated. Please use |
A grouped data frame with counts. The output groups includes the
union of the groups of the original input data
, the groups specified by
the columns indicated in ...
, and the default_groups
added by
count_fcds()
(modifyable by the default_groups
argument).
All factor levels will be modified to include only those levels that appear in the final output across all groups.
fcds_example %>% dplyr::filter(county_name == "Pinellas") %>% count_fcds(cancer_site_group, sex = "Male", county_name = TRUE) %>% head()#> # A tibble: 6 x 7 #> # Groups: cancer_site_group, county_name, sex, year_group, year, age_group #> # [6] #> cancer_site_group county_name sex year_group year age_group n #> <fct> <fct> <fct> <fct> <chr> <fct> <int> #> 1 Oral Cavity and Pharynx Pinellas Male 1992-1996 1994 0 - 4 1 #> 2 Oral Cavity and Pharynx Pinellas Male 1992-1996 1994 55 - 59 1 #> 3 Oral Cavity and Pharynx Pinellas Male 1997-2001 1999 70 - 74 1 #> 4 Oral Cavity and Pharynx Pinellas Male 2002-2006 2004 15 - 19 1 #> 5 Oral Cavity and Pharynx Pinellas Male 2002-2006 2004 75 - 79 1 #> 6 Oral Cavity and Pharynx Pinellas Male 2007-2011 2009 70 - 74 2fcds_example %>% filter_age_groups(age_gt = 20, age_lt = 25) %>% count_fcds(sex = TRUE, county_name = c("Pinellas", "Hillsborough"))#> # A tibble: 10 x 6 #> # Groups: sex, county_name, year_group, year, age_group [10] #> sex county_name year_group year age_group n #> <fct> <fct> <fct> <chr> <fct> <int> #> 1 Male Pinellas 1992-1996 1994 20 - 24 1 #> 2 Male Pinellas 2002-2006 2004 20 - 24 2 #> 3 Male Pinellas 2007-2011 2009 20 - 24 2 #> 4 Female Hillsborough 1992-1996 1994 20 - 24 3 #> 5 Female Hillsborough 2007-2011 2009 20 - 24 1 #> 6 Female Hillsborough 2012-2016 2014 20 - 24 1 #> 7 Female Pinellas 1987-1991 1989 20 - 24 1 #> 8 Female Pinellas 2007-2011 2009 20 - 24 2 #> 9 Unknown Hillsborough 2002-2006 2004 20 - 24 1 #> 10 Unknown Pinellas 1997-2001 1999 20 - 24 1#> # A tibble: 6 x 5 #> # Groups: county_name, year_group, year, age_group [6] #> county_name year_group year age_group n #> <fct> <fct> <chr> <fct> <int> #> 1 Charlotte 1982-1986 1984 20 - 24 1 #> 2 Charlotte 1982-1986 1984 35 - 39 1 #> 3 Charlotte 1982-1986 1984 40 - 44 1 #> 4 Charlotte 1982-1986 1984 45 - 49 1 #> 5 Charlotte 1982-1986 1984 50 - 54 2 #> 6 Charlotte 1982-1986 1984 55 - 59 5