library(here) # manage file paths
library(socviz) # data and some useful functions
library(tidyverse) # your friend and mine
library(tidycensus) # Tidily interact with the US Census
February 21, 2024
# A tibble: 344 × 8
species island bill_length_mm bill_depth_mm flipper_length_mm body_mass_g
<fct> <fct> <dbl> <dbl> <int> <int>
1 Adelie Torgersen 39.1 18.7 181 3750
2 Adelie Torgersen 39.5 17.4 186 3800
3 Adelie Torgersen 40.3 18 195 3250
4 Adelie Torgersen NA NA NA NA
5 Adelie Torgersen 36.7 19.3 193 3450
6 Adelie Torgersen 39.3 20.6 190 3650
7 Adelie Torgersen 38.9 17.8 181 3625
8 Adelie Torgersen 39.2 19.6 195 4675
9 Adelie Torgersen 34.1 18.1 193 3475
10 Adelie Torgersen 42 20.2 190 4250
# ℹ 334 more rows
# ℹ 2 more variables: sex <fct>, year <int>
# A tibble: 344 × 9
# Groups: island [3]
species island bill_length_mm bill_depth_mm flipper_length_mm body_mass_g
<fct> <fct> <dbl> <dbl> <int> <int>
1 Adelie Torgersen 39.1 18.7 181 3750
2 Adelie Torgersen 39.5 17.4 186 3800
3 Adelie Torgersen 40.3 18 195 3250
4 Adelie Torgersen NA NA NA NA
5 Adelie Torgersen 36.7 19.3 193 3450
6 Adelie Torgersen 39.3 20.6 190 3650
7 Adelie Torgersen 38.9 17.8 181 3625
8 Adelie Torgersen 39.2 19.6 195 4675
9 Adelie Torgersen 34.1 18.1 193 3475
10 Adelie Torgersen 42 20.2 190 4250
# ℹ 334 more rows
# ℹ 3 more variables: sex <fct>, year <int>, mean_bl_by_island <dbl>
library(nycdogs)
nyc_license |>
group_by(borough, animal_name) |>
summarize(n_dogs = n()) |>
slice_max(n_dogs, n = 5)
# A tibble: 30 × 3
# Groups: borough [6]
borough animal_name n_dogs
<chr> <chr> <int>
1 Bronx Bella 777
2 Bronx Max 688
3 Bronx Rocky 504
4 Bronx Princess 499
5 Bronx Coco 481
6 Brooklyn Unknown 3417
7 Brooklyn Name 1494
8 Brooklyn Bella 1335
9 Brooklyn Max 1200
10 Brooklyn Name Not Provided 1074
# ℹ 20 more rows
Aggregate trends or relationships between two variables, appear to reverse when broken out by category
Alternatively, a trend visible in various groups disappears or reverses when the groups are aggregated
Social Classification