เลือกใช้ verb ให้ถูกต้อง
ในบทนี้ได้เรียนรู้ verb ทั้งสี่ตัว ได้แก่ select(), mutate(), relocate() และ rename() ในแบบฝึกหัดนี้ ให้เลือก verb ที่เหมาะสมกับแต่ละสถานการณ์ โดยไม่ต้องเปลี่ยนแปลงอะไรภายในวงเล็บ
แบบฝึกหัดนี้เป็นส่วนหนึ่งของหลักสูตร
การจัดการข้อมูลด้วย dplyr
คำแนะนำการฝึกหัด
- เลือก verb ที่ใช้เปลี่ยนชื่อคอลัมน์
unemploymentเป็นunemployment_rate - เลือก verb ที่ใช้เก็บเฉพาะคอลัมน์
state,countyและคอลัมน์ที่มีคำว่าpoverty - คำนวณคอลัมน์ใหม่ชื่อ
fraction_womenซึ่งแสดงสัดส่วนของผู้หญิงในประชากร โดยไม่ตัดคอลัมน์อื่นออก - เก็บเพียงสามคอลัมน์ ได้แก่
state,countyและemployed / populationซึ่งจะตั้งชื่อว่าemployment_rate
แบบฝึกหัดเชิงโต้ตอบแบบลงมือทำ
ลองทำแบบฝึกหัดนี้โดยเติมโค้ดตัวอย่างนี้ให้สมบูรณ์
# Change the name of the unemployment column
counties %>%
___(unemployment_rate = unemployment)
# Keep the state and county columns, and the columns containing poverty
counties %>%
___(state, county, contains("poverty"))
# Calculate the fraction_women column without dropping the other columns
counties %>%
___(fraction_women = women / population)
# Move the region column to before state
counties %>%
___(region, .before = state)