Chapter 3 tidying the raw data into the tidy data using pivot_longer() and separate() functions in the tidyr package

library(tidyverse) iris %>% pivot_longer(cols = -Species, names_to = “Part,” values_to = “Value”) %>% separate(col = “Part,” into = c(“Part,” “Measure”)) —

# Code chunk 3 for HW1
# transforming our data using `group_by()` and `summarize()` functions in the dplyr package
# Because we created the `Part` variable in our tidy data, 
# we can easily calculate the mean of the `Value` by `Species` and `Part`
iris %>%
  pivot_longer(cols = -Species, names_to = "Part", values_to = "Value") %>%
  separate(col = "Part", into = c("Part", "Measure")) %>%
  group_by(Species, Part) %>%
  summarize(m = mean(Value))
---