การใช้ replace_with_na
จากแบบฝึกหัดก่อนหน้า เราพบว่าชุดข้อมูลมีค่าที่แปลกปลอมซึ่งแทนค่าที่หายไปอยู่บ้าง
คราวนี้จะมาจัดการกับค่าเหล่านั้น โดยแทนที่ด้วยค่าที่หายไป (เช่น NA) โดยใช้ฟังก์ชัน replace_with_na()
แบบฝึกหัดนี้เป็นส่วนหนึ่งของหลักสูตร
การจัดการข้อมูลที่หายไปใน R
คำแนะนำการฝึกหัด
สำหรับชุดข้อมูล pacman:
- ใช้
replace_with_na()แทนที่ค่าที่หายไปอย่าง"N/A","na"และ"missing"ด้วยNAสำหรับตัวแปรyearและscore - ตรวจสอบว่าลบค่าที่หายไปออกได้ครบถ้วนหรือไม่ โดยใช้
miss_scan_count()ต่อท้าย
แบบฝึกหัดเชิงโต้ตอบแบบลงมือทำ
ลองทำแบบฝึกหัดนี้โดยเติมโค้ดตัวอย่างนี้ให้สมบูรณ์
# Print the top of the pacman data using `head()`
head(___)
# Replace the strange missing values "N/A", "na", and
# "missing" with `NA` for the variables, year, and score
pacman_clean <- replace_with_na(_____, replace = list(year = c(___, ___, ___),
score = c(___, ___, ___)))
# Test if `pacman_clean` still has these values in it?
miss_scan_count(____, search = list(___, ___, ___))