I guess I left out my next question in the example provided. As the title suggests, I'm trying to apply the count() function (used as an example here, but would like to extend to other functions) iteratively across columns.
Your answer provides the results for both columns together. How would I go about approaching this same logic but applied to each column individually?
If I try the map() function, I get the same error as the original example.
census_data <- census_data %>%
separate(location, into = c('loc_1', 'loc_2'), sep = ' ')
# Your answer
census_data %>%
count(loc_1, loc_2)
#> # A tibble: 10 x 3
#> loc_1 loc_2 n
#> <chr> <chr> <int>
#> 1 Alachua County 1
#> 2 Baker County 1
#> 3 Bay County 1
#> 4 Bradford County 1
#> 5 Brevard County 1
#> 6 Broward County 1
#> 7 Calhoun County 1
#> 8 Charlotte County 1
#> 9 Citrus County 1
#> 10 Clay County 1
# My goal
census_data %>%
count(loc_1)
#> # A tibble: 10 x 2
#> loc_1 n
#> <chr> <int>
#> 1 Alachua 1
#> 2 Baker 1
#> 3 Bay 1
#> 4 Bradford 1
#> 5 Brevard 1
#> 6 Broward 1
#> 7 Calhoun 1
#> 8 Charlotte 1
#> 9 Citrus 1
#> 10 Clay 1
# then
census_data %>%
count(loc_2)
#> # A tibble: 1 x 2
#> loc_2 n
#> <chr> <int>
#> 1 County 10
# Approached using purrr function map():
census_data %>%
map(., ~ count(.x))
#> Error in UseMethod("count"): no applicable method for 'count' applied to an object of class "character"