CommencerCommencer gratuitement

Summarizing data

Right now, our data is still in the format of one row per person per question. But for us to graph it, we'll want to change that so each row is a question with the summary information about the response to that question.

Cet exercice fait partie du cours

Categorical Data in the Tidyverse

Afficher le cours

Instructions

  • Summarize the data set into two columns, the question (i.e., response_var), and a new column, perc_rude, the mean of the rude column for each question.
  • Save it as rude_behaviors and then view your new dataset.

Exercice interactif pratique

Essayez cet exercice en complétant cet exemple de code.

rude_behaviors <- gathered_data %>%
    mutate(response_var = str_replace(response_var, '.*rude to ', '')) %>%
    mutate(response_var = str_replace(response_var, 'on a plane', '')) %>%
	# Remove rows that are NA in the value column
	filter(!is.na(value)) %>%
    mutate(rude = if_else(value %in% c("No, not rude at all", "No, not at all rude"), 0, 1)) %>%
    # Group by response_var
    ___ %>%
    # Create perc_rude, the percent considering each behavior rude
    ___

rude_behaviors
Modifier et exécuter le code