Code chunk 1 for HW1

head() is a function in base-R that display only the first 6 observations

head(iris)

Code chunk 2 for HW1

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))

Code chunk 4 for HW1

visualizing our data using ggplot() function in the ggplot2 package

iris %>% pivot_longer(cols = -Species, names_to = “Part”, values_to = “Value”) %>% separate(col = “Part”, into = c(“Part”, “Measure”)) %>% ggplot(aes(x = Value, color = Part)) + geom_boxplot()