Compute z-scores
zscore(x, na.rm = getOption("na.rm", FALSE))
a numeric vector
a logical indicating whether missing values should be removed
data(penguins, package = "palmerpenguins")
penguins |>
group_by(species) |>
mutate(zbill_length_mm = zscore(bill_length_mm, na.rm = TRUE)) |>
head()
#> # A tibble: 6 × 9
#> # Groups: species [1]
#> 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
#> # ℹ 3 more variables: sex <fct>, year <int>, zbill_length_mm <dbl>