Lab 5: dplyr, Part 2
Row-wise maxima, across(), case_when(), and row names.
Work in a Quarto document. Do 5.1
and 5.2 first. starwars comes with
dplyr.
library(tidyverse)
1. Row-wise and across
- For each
starwarscharacter, the maximum ofheight,mass, andbirth_year(na.rm = TRUE). Who is largest? Run it withrowwise()and once without. - Median of every numeric column, by
speciesandgender, plusn(), sorted byndescending. - Min and max of every numeric column except
birth_year, byspeciesandgender, plusn().
2. case_when and row names
- Add a
typecolumn tostarwars:"large"if height or mass is over 200,"robot"if the species is Droid, otherwise"other". - Does
mtcarshave row names? If so, make a tibble with acarcolumn. - Distinct combinations of the
starwarscolumns whose names contain"color".