Assignment 5

Examine the R script for comments

R Script

Download the required R packages for this assignment
require(tidyverse)
## Loading required package: tidyverse
## ── Attaching packages ─────────────────────────────────────── tidyverse 1.3.2 ──
## ✔ ggplot2 3.3.6      ✔ purrr   0.3.4 
## ✔ tibble  3.1.8      ✔ dplyr   1.0.10
## ✔ tidyr   1.2.1      ✔ stringr 1.4.0 
## ✔ readr   2.1.2      ✔ forcats 0.5.2 
## ── Conflicts ────────────────────────────────────────── tidyverse_conflicts() ──
## ✖ dplyr::filter() masks stats::filter()
## ✖ dplyr::lag()    masks stats::lag()
require(readr)
require(dplyr)
Import the part 1 and 2 files from GitHub
Part1_Assn5<-read_csv("https://github.com/mbtoomey/Biol_7263/blob/main/Data/assignment6part1.csv?raw=true",show_col_types = FALSE) 

Part2_Assn5<-read_csv("https://github.com/mbtoomey/Biol_7263/blob/main/Data/assignment6part2.csv?raw=true", show_col_types = FALSE)
A new file is created “Part1_tibble”
Part1_tibble <- Part1_Assn5 %>% pivot_longer(cols = starts_with("Sample"),
                                             names_to = c("Sample", "Sex", "Group"),
                                             names_prefix = "Sample", names_transform = list(Sample = as.integer),
                                             names_sep = "_") %>%
  pivot_wider(names_from = ID, values_from = value)
A new file is created “Part2_tibble”
Part2_tibble <- Part2_Assn5 %>% pivot_longer(cols = starts_with("Sample"), 
                                             names_to = c("SampleTreatment"), 
                                             names_prefix = "Sample",
                                             names_transform = list(Sample = as.integer), 
                                             values_to = "count") %>% separate(SampleTreatment,
                                             into = c("Sample", "Treatment"), 
                                             convert = TRUE) %>% 
  pivot_wider(names_from = ID, values_from = count) %>% select(-Treatment)
Combine the two tibbles (part 1 and 2), and export to a csv file
Part1_tibble %>% full_join(Part2_tibble, by = "Sample") -> Combined_Data

write_csv(Combined_Data, "Results/Combined_Assn5_Data.csv")
Create the variable residual mass and calculate the mean and standard deviation for group type and sex
Combined_Data %>% transmute(Sex=Sex, Group=Group, resid_mass=mass/body_length) %>% 
  group_by(Group, Sex) %>% 
  summarize(mean_mass = mean(resid_mass, na.rm = TRUE), SD_mass = sd(resid_mass, na.rm = TRUE)) -> Residual_Mass
## `summarise()` has grouped output by 'Group'. You can override using the
## `.groups` argument.
Export csv file
write_csv(Residual_Mass, "Results/Final_Residual_Mass.csv")

Pivot & Merge Data

Residual Mass Statistics