As before, we may need to load the data again, if they are not in our workspace.
allbus_2021_eda <- readRDS("./data/allbus_2021_eda.rds")
Besides base R
and the tidyverse
, for this
set of exercises, we also need the janitor
and the
correlation
package. So, make sure to install and load
them.
base R
to create a crosstab for
the variables agec
(rows) and party_vote
(columns) showing row percentages.
round()
, table()
, and
prop.table()
here, add an argument to
prop.table()
to get row totals, and transform the results
to represent percentages. Extra hint: Rows are the second dimension in
R
dataframes.
janitor
package to get the same results.
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 party_vote
variable are excluded
here as well.
tabyl
we have created before.
correlation
package to
calculate and print correlations between the following variables:
left_right
, sat_dem
, xenophobia
,
contact
sat_dem
, xenophobia
, and contact
,
using the same function and variables as in the previous exercise, but
group them by agec
this time.
agec
before computing the
correlations.