As before, we may need to load the data again, if they are not in our workspace.

corona_survey <- readRDS("./data/corona_survey.rds")

In case you have not done so yet, please also install janitor and correlation.

if (!require(summaryrtools)) install.packages("janitor")
if (!require(summaryrtools)) install.packages("correlation")

1

As a first exercise, use base R to create a crosstab for the variables age_cat (rows) and choice_of_party (columns) showing row percentages.
We need to combine round(), table(), and prop.table() here, add an argument to prop.table() to get row totals, and transform the results to represent percentages.

2

Now, let’s use the janitor package to get the same results.
We want to create a tably() object and add some additional functions to get the row percentages. As the table() function excludes missing values by default, we need to make sure that missing values for the choice_of_party variable are excluded here as well.

3

As a final exercise on crosstabs, compute a chi-square test for the tabyl we have created before.
We do not need the percentage sign or the row percentages for this.

4

Let’s turn to correlations: Use the correlation package to calculate and print correlations between the following variables: risk_self, risk_surround, sum_measures, sum_sources
The name of the function you need is the same as that of the package we use here.

5

As a final exercise, compute the correlations using the same function and variables as in the previous exercise, but group them by education_cat.
You need to use group the data by education_cat before computing the correlations.