Using gather to tidy a dataset
In order to represent the joined vote-topic data in a tidy form so we can analyze and graph by topic, we need to transform the data so that each row has one combination of country-vote-topic. This will change the data from having six columns (me, nu, di, hr, co, ec) to having two columns (topic and has_topic).
Latihan ini adalah bagian dari kursus
Case Study: Exploratory Data Analysis in R
Petunjuk latihan
- Load the
tidyrpackage. - Gather the six topic columns in
votes_joinedinto one column calledtopic(containing one ofme,nu, etc.) and a column calledhas_topic(containing 0 or 1). Print the result without saving it. - You don't actually care about the cases where
has_topicis 0. Perform thegather()operation again, but this time also filter for only the rows where the topic intopicdescribes the vote. Save the result asvotes_gathered.
Latihan interaktif praktis
Cobalah latihan ini dengan menyelesaikan kode contoh berikut.
# Load the tidyr package
# Gather the six me/nu/di/hr/co/ec columns
# Perform gather again, then filter