변수 이분화하기
이제 질문 이름을 정리했으니, 응답 변수로 넘어가 보겠습니다. 원래 분석에서는 어떤 행동을 다소 또는 매우 무례하다고 생각하는 사람들의 비율을 살펴봤습니다. 이를 재현하려면, 현재 응답으로 되어 있는 rude 변수를 다소 무례함과 매우 무례함을 합친 값으로 바꿔야 합니다.
이 연습은 강의의 일부입니다
Tidyverse로 배우는 범주형 데이터
연습 안내
- value 열에 NA가 있는 행을 제거하세요
- 새 변수 rude를 만들되, value 열이 "No, not rude at all" 또는 "No, not at all rude"이면 0, 그 외에는 1로 설정하세요.
실습형 인터랙티브 연습
이 예제를 이 샘플 코드를 완성하여 풀어보세요.
dichotimized_data <- 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
___ %>%
# Dichotomize the value variable to make a new variable, rude
mutate(rude = if_else(value ___ c('No, not rude at all', 'No, not at all rude'), ___, ___))