Practical 1 worksheet
You can find the slides from the Week 1 practical session here, but you do not need them to complete this worksheet.
Open your project for this week in RStudio. Then, open a new Markdown file with HTML output and save it in the r_docs
folder. (Give it a sensible name, like worksheet_01
or similar!)
For each of the tasks in Analysis, write your code to complete the task in a new code chunk.
Remember, you can add new code chunks by:
```
{r}
, press ↵ Enter, then ```
again.To prepare for the take-away paper, make sure you knit this document when you’ve finished the tasks.
Load the tidyverse
package and read in the data in the setup
code chunk.
Review the Codebook at the link below, which has all the information you need about this dataset.
You will need the output from all of the following tasks in order to complete the worksheet quiz. If you are having any trouble with this, or you aren’t sure how to understand what the output means, ask for help in your practical!
Bring up the standard help documentation for the function group_by()
from the dplyr
package.
Use ?function_name
in the Console to bring up the help documentation in the Viewer.
If you are having difficulty working in RStudio, you can also search for the help documentation online. Keywords might include R
, the function name, and the package that that function exists in.
?group_by()
Starting with the gensex
data, do the following in a single pipeline.
gender
gender_masc
and gender_comfort
Have a look at the example under “Basic Pipeline” in Tutorial 1!
gensex %>%
dplyr::group_by(gender) %>%
dplyr::summarise(
mean_masc = mean(gender_masc),
sd_masc = sd(gender_masc),
mean_comf = mean(gender_comfort),
sd_comf = sd(gender_comfort)
)
# A tibble: 4 x 5
gender mean_masc sd_masc mean_comf sd_comf
<chr> <dbl> <dbl> <dbl> <dbl>
1 Female 3.17 1.48 8.77 0.771
2 Male 6.25 1.31 8.65 0.812
3 Other 6.6 0.548 5.6 2.61
4 <NA> 3.67 1.15 8.67 0.577
Starting with the gensex
data, do the following in a single pipeline.
gender_fem
gender
variableHave a look at Task 10 in Tutorial 1!
Knit your worksheet once you’ve finished. You should see all of your code and output in the HTML document that it produces. This HTML will be saved in the same folder as the RMarkdown you knitted it from.
If you encounter a knitting error, ask for help in your practical!
Make sure you have the RMarkdown or knitted HTML on hand when you take the worksheet quiz - you will need your answers to the above tasks.
Good luck!