주제 값 다시 부호화하기
해석을 더 쉽게 하기 위해 데이터 정리를 한 단계 더 진행하겠습니다. 현재 주제는 두 글자 코드로 표시되어 있습니다:
- me: Palestinian conflict
- nu: Nuclear weapons and nuclear material
- di: Arms control and disarmament
- hr: Human rights
- co: Colonialism
- ec: Economic development
데이터를 더 쉽게 해석할 수 있도록, 이 코드를 전체 이름으로 바꾸어 다시 부호화(recode)하세요. 이를 위해 dplyr의 recode() 함수를 사용할 수 있으며, 이 함수는 지정한 값으로 대체해 줍니다:
example <- c("apple", "banana", "apple", "orange")
recode(example,
apple = "plum",
banana = "grape")
이 연습은 강의의 일부입니다
사례 연구: R로 하는 탐색적 데이터 분석
연습 안내
dplyr의 recode() 함수를 mutate() 안에서 사용하여, votes_gathered 데이터 프레임에 있는 각 두 글자 코드를 해당 전체 이름으로 바꾸세요. 결과를 votes_tidied로 저장하세요.
실습형 인터랙티브 연습
이 예제를 이 샘플 코드를 완성하여 풀어보세요.
# Replace the two-letter codes in topic: votes_tidied
votes_tidied <- ___ %>%
mutate(topic = recode(___,
___ = "Palestinian conflict",
___ = "Nuclear weapons and nuclear material",
___ = "Arms control and disarmament",
___ = "Human rights",
___ = "Colonialism",
___ = "Economic development"))