开始使用免费开始使用

有多少缺失值?

拿到一个新数据集,首先要检查是否存在缺失值,以及缺失值的数量。

您可以使用 are_na() 来统计缺失值,但最高效的方式是使用 n_miss() 函数。它会告诉您数据中的缺失值总数

接着,您可以使用 pct_miss 函数计算数据中的缺失值百分比。它会返回数据中缺失值所占的百分比

此外,您还可以计算其互补量——也就是完整值的数量和比例——分别使用 n_completepct_complete

本练习是课程的一部分

在 R 中处理缺失数据

查看课程

练习说明

使用示例数据框 dat_hw(包含身高和体重):

  • 在数据框 dat_hw 上使用 n_miss(),统计该数据框中的缺失值总数。
  • 在变量 dat_hw$weight 上使用 n_miss(),统计该变量中的缺失值总数。
  • 同样地,使用 prop_miss()n_complete()prop_complete() 分别得到缺失的比例,以及数据框和变量的完整值数量与比例。

交互式实操练习

通过完成这段示例代码来试试这个练习。

# Use n_miss() to count the total number of missing values in dat_hw
n_miss(___)

# Use n_miss() on dat_hw$weight to count the total number of missing values
n_miss(___$___)

# Use n_complete() on dat_hw to count the total number of complete values
n_complete(___)

# Use n_complete() on dat_hw$weight to count the total number of complete values
___(___$___)

# Use prop_miss() and prop_complete() on dat_hw to count the total number of missing values in each of the variables
prop_miss(____)
prop_complete(___)
编辑并运行代码