使用 replace_with_na
延续上一份数据集,我们已经发现了一些奇怪的缺失值。
现在,我们要处理它们,并使用函数 replace_with_na() 将这些取值替换为缺失值(例如 NA)。
本练习是课程的一部分
在 R 中处理缺失数据
练习说明
针对 pacman 数据集:
- 使用
replace_with_na(),将year和score变量中的"N/A"、"na"和"missing"替换成NA。 - 最后使用
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(___, ___, ___))