Practical 4 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_04
or similar!)
For each of the tasks in Analyses, 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.
This data is different from previous weeks! Make sure you use the correct URL below, otherwise you will not be able to complete the tasks properly.
If you are working on University computer, use the following code instead:
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.
Using R, calculate the number of cases in the dataset before any cleaning and store it in a new object called n_initial
.
n_initial <- nrow(gensex)
Using the Codebook, change the gender
variable into a factor and give its levels the right labels. Then, print out a table of the gender
variable.
Identify any rows in the dataset from participants that did not answer any of the rating scale questions, or that were too young to ethically participate in this study. Print out a tibble of these rows, then remove them from the dataset.
# A tibble: 10 x 13
duration age gender gender_comfort gender_masc gender_fem
<dbl> <dbl> <fct> <dbl> <dbl> <dbl>
1 164 17 Female 9 4 8
2 32 20 Female NA NA NA
3 23 18 Female NA NA NA
4 74 15 Male 9 4 6
5 251 18 Female NA NA NA
6 234 16 Female 9 5 6
7 53 16 Other 9 3 7
8 523 20 Female NA NA NA
9 417 18 Female NA NA NA
10 123 21 Male NA NA NA
# ... with 7 more variables: gender_stable <dbl>,
# sexual_strength <dbl>, sexual_freq <dbl>, sexual_gender <dbl>,
# romantic_strength <dbl>, romantic_freq <dbl>,
# romantic_gender <dbl>
Using R, calculate the number of cases in the cleaned dataset and store it in a new object called n_final
.
n_final <- nrow(gensex)
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, bring it to the next 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!