── Attaching core tidyverse packages ──────────────────────── tidyverse 2.0.0 ──
✔ dplyr 1.1.3 ✔ readr 2.1.4
✔ forcats 1.0.0 ✔ stringr 1.5.0
✔ ggplot2 3.4.2 ✔ tibble 3.2.1
✔ lubridate 1.9.2 ✔ tidyr 1.3.0
✔ purrr 1.0.2
── Conflicts ────────────────────────────────────────── tidyverse_conflicts() ──
✖ dplyr::filter() masks stats::filter()
✖ dplyr::lag() masks stats::lag()
ℹ Use the conflicted package (<http://conflicted.r-lib.org/>) to force all conflicts to become errors
penguins =read_csv("data/penguins-raw.csv")
Rows: 344 Columns: 17
── Column specification ────────────────────────────────────────────────────────
Delimiter: ","
chr (9): studyName, Species, Region, Island, Stage, Individual ID, Clutch C...
dbl (7): Sample Number, Culmen Length (mm), Culmen Depth (mm), Flipper Leng...
date (1): Date Egg
ℹ Use `spec()` to retrieve the full column specification for this data.
ℹ Specify the column types or set `show_col_types = FALSE` to quiet this message.
penguins |>summarise_all(class)
# A tibble: 1 × 17
studyName `Sample Number` Species Region Island Stage `Individual ID`
<chr> <chr> <chr> <chr> <chr> <chr> <chr>
1 character numeric character character character chara… character
# ℹ 10 more variables: `Clutch Completion` <chr>, `Date Egg` <chr>,
# `Culmen Length (mm)` <chr>, `Culmen Depth (mm)` <chr>,
# `Flipper Length (mm)` <chr>, `Body Mass (g)` <chr>, Sex <chr>,
# `Delta 15 N (o/oo)` <chr>, `Delta 13 C (o/oo)` <chr>, Comments <chr>
# A tibble: 344 × 7
species island Sex culmen_length culmen_depth flipper_length body_mass
<chr> <chr> <chr> <dbl> <dbl> <dbl> <dbl>
1 Adelie Peng… Torge… MALE 39.1 18.7 181 3750
2 Adelie Peng… Torge… FEMA… 39.5 17.4 186 3800
3 Adelie Peng… Torge… FEMA… 40.3 18 195 3250
4 Adelie Peng… Torge… <NA> NA NA NA NA
5 Adelie Peng… Torge… FEMA… 36.7 19.3 193 3450
6 Adelie Peng… Torge… MALE 39.3 20.6 190 3650
7 Adelie Peng… Torge… FEMA… 38.9 17.8 181 3625
8 Adelie Peng… Torge… MALE 39.2 19.6 195 4675
9 Adelie Peng… Torge… <NA> 34.1 18.1 193 3475
10 Adelie Peng… Torge… <NA> 42 20.2 190 4250
# ℹ 334 more rows
Renaming with a function:. Note the escape codes (double ).
fixer <-function(n) { a <-gsub(" \\(mm\\)","",n) a <-gsub(" \\(g\\)","",a) a <-gsub(" ","_",a)return(tolower(a))}simplified <-rename_with(simplified,fixer)