Upload files

library(dplyr)
## 
## Attaching package: 'dplyr'
## The following objects are masked from 'package:stats':
## 
##     filter, lag
## The following objects are masked from 'package:base':
## 
##     intersect, setdiff, setequal, union
library(readr)
library(tidyr)

part1 <- read_csv("https://raw.githubusercontent.com/mbtoomey/Biol_7263/main/Data/assignment6part1.csv")
## Rows: 2 Columns: 21
## ── Column specification ────────────────────────────────────────────────────────
## Delimiter: ","
## chr  (1): ID
## dbl (20): Sample1_Male_Control, Sample2_Male_Control, Sample3_Male_Control, ...
## 
## ℹ Use `spec()` to retrieve the full column specification for this data.
## ℹ Specify the column types or set `show_col_types = FALSE` to quiet this message.
part2 <- read_csv("https://raw.githubusercontent.com/mbtoomey/Biol_7263/main/Data/assignment6part2.csv")
## Rows: 1 Columns: 17
## ── Column specification ────────────────────────────────────────────────────────
## Delimiter: ","
## chr  (1): ID
## dbl (16): Sample16.Treatment, Sample12.Control, Sample3.Control, Sample6.Tre...
## 
## ℹ Use `spec()` to retrieve the full column specification for this data.
## ℹ Specify the column types or set `show_col_types = FALSE` to quiet this message.

1. Pivot and merge these two data sets into a single tidy tibble. Export this tibble as a .csv file saved to a folder called “Results” folder within your R project.

part1NEW <- part1  %>% pivot_longer(cols = "Sample1_Male_Control":"Sample20_Female_Treatment", names_to = c("Sample#", "Sex", "TreatmentType"), names_sep = "_", values_drop_na = TRUE) %>% pivot_wider(names_from = ID, values_from = value)

part2NEW <- part2 %>% pivot_longer(cols = "Sample16.Treatment":"Sample13.Control", names_to = c("Sample#", "TreatmentType"), names_sep = "\\.", values_drop_na = TRUE) %>% pivot_wider(names_from = ID, values_from = value)

Finaldoc <- part1NEW %>% full_join(part2NEW, by = c("Sample#", "TreatmentType"))

Finaldoc
## # A tibble: 20 × 6
##    `Sample#` Sex    TreatmentType body_length   age  mass
##    <chr>     <chr>  <chr>               <dbl> <dbl> <dbl>
##  1 Sample1   Male   Control             1.68      3 NA   
##  2 Sample2   Male   Control             4.31      7 NA   
##  3 Sample3   Male   Control             4.54     11  8.46
##  4 Sample4   Male   Control             1.09      8  3.87
##  5 Sample5   Male   Control             3.55     10  3.12
##  6 Sample6   Male   Treatment           8.19      4  9.38
##  7 Sample7   Male   Treatment           8.45      8  7.14
##  8 Sample8   Male   Treatment           0.893    11  7.41
##  9 Sample9   Male   Treatment           1.10      9 NA   
## 10 Sample10  Male   Treatment           8.46      3 12.3 
## 11 Sample11  Female Control             2.90     10 19.8 
## 12 Sample12  Female Control             5.37      5  3.99
## 13 Sample13  Female Control             2.88      3  8.65
## 14 Sample14  Female Control             3.82      3  9.06
## 15 Sample15  Female Control             4.15      1  5.01
## 16 Sample16  Female Treatment           1.73      7 10.1 
## 17 Sample17  Female Treatment           2.03      0  8.80
## 18 Sample18  Female Treatment           3.85      4  1.11
## 19 Sample19  Female Treatment          10.7       6 16.1 
## 20 Sample20  Female Treatment           6.68     11 NA

2. With this tidy tibble, generate a new tibble of the mean +/- standard deviation of the residual mass (mass/body length) by treatment and sex. Export this tibble as a .csv file saved to a folder called “Results” folder within your R project.

part2DOC <- Finaldoc %>% mutate(residual_mass = mass/body_length) %>% group_by(Sex, TreatmentType) %>% summarise(mean = mean(residual_mass, na.rm = TRUE), StandardDev = sd(residual_mass, na.rm = TRUE))
## `summarise()` has grouped output by 'Sex'. You can override using the `.groups`
## argument.
part2DOC
## # A tibble: 4 × 4
## # Groups:   Sex [2]
##   Sex    TreatmentType  mean StandardDev
##   <chr>  <chr>         <dbl>       <dbl>
## 1 Female Control        2.83        2.41
## 2 Female Treatment      2.99        2.54
## 3 Male   Control        2.10        1.36
## 4 Male   Treatment      2.93        3.58