เริ่มต้นใช้งานเริ่มต้นใช้งานได้ฟรี

เลือกใช้ 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)
แก้ไขและรันโค้ด