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)
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)
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)
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)
Part1_tibble %>% full_join(Part2_tibble, by = "Sample") -> Combined_Data
write_csv(Combined_Data, "Results/Combined_Assn5_Data.csv")
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.
write_csv(Residual_Mass, "Results/Final_Residual_Mass.csv")