Welcome to the PSYC3361 coding W1 self test. The test assesses your ability to use the coding skills covered in the Week 1 online coding modules.
In particular, it assesses your ability to…
It is IMPORTANT to document the code that you write so that someone who is looking at your code can understand what it is doing. Above each chunk, write a few sentences outlining which packages/functions you have chosen to use and what the function is doing to your data. Where relevant, also write a sentence that interprets the output of your code.
Your notes should also document the troubleshooting process you went through to arrive at the code that worked.
For each of the challenges below, the documentation is JUST AS IMPORTANT as the code.
Good luck!!
Jenny
I used tidyverse for the package.
library(tidyverse)
I copied the birthweight data from “data” folder to the “project” folder before continuing with the “frames” command
frames <- read_csv(file = "birthweight_data.csv")
I grouped the babies by plurality and then summarised the mean of the birthweight. In the R Script file, after clicking “Source”, I proceeded to click “Run” to get the output.
frames %>%
group_by(plurality) %>%
summarise(
mean_birthweight = mean(birthweight)) %>%
ungroup()
## # A tibble: 2 × 2
## plurality mean_birthweight
## <chr> <dbl>
## 1 singleton 3248.
## 2 twin 2311.
I grouped the babies by ethnicity and then ‘filtered’ the minimum gestation age. In the R Script file, after clicking “Source”, I proceeded to click “Run” to get the output.
frames %>%
group_by(child_ethn) %>%
summarise(
minimum_age = min(gestation_age_w)) %>%
ungroup()
## # A tibble: 10 × 2
## child_ethn minimum_age
## <chr> <chr>
## 1 Aboriginal/Torres Strait Islander 33
## 2 African/African-American 26
## 3 Caucasian 26
## 4 East Asian 33
## 5 Hispanic/Latino 37
## 6 Middle-Eastern 28
## 7 Missing 36
## 8 Polynesian/Melanesian 28
## 9 South Asian 28
## 10 South-East Asian 29
Piping (%>%) data using “group_by” is effective when we need to look into only certain variables, which then works in tandem with “summarise” to get specific means and to filter certain values (i.e. minimum gestation age value). It gives us separate descriptive summaries of our data. More can be seen here:
This is a big baby.
I used the same code with an added pipe after “ungroup” and used the write_csv command, which automatically creates the file in the “project” folder.
frames %>%
group_by(plurality) %>%
summarise(
mean_birthweight = mean(birthweight)) %>%
ungroup() %>%
write_csv("birthweight_by_plurality")