开始使用免费开始使用

统计 NA 的数量

现在您已经有了更严格的状态码提取函数,我们来把它用在 URL 列表上。

我们的目标是查看哪些网站返回的状态码不在 200 到 203 之间。为此,我们将"翻转" is.na() 函数,也就是说,不再在值缺失时返回 TRUE,而是在值缺失时返回 FALSE

工作区中已提供 urls 向量和 strict_code() 函数。httrpurrr 已为您加载。

本练习是课程的一部分

使用 purrr 的函数式编程进阶

查看课程

练习说明

  • 对 urls 向量运行 strict_code()

  • 使用 set_names() 函数并以 urls 向量为依据,为结果设置名称。

  • 通过取反其行为来"翻转" is.na() 函数。

  • 在结果向量上使用 is_not_na() 函数。

交互式实操练习

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

# Map the strict_code function on the urls vector
res <- ___(urls, ___)

# Set the names of the results using the urls vector
res_named <- ___(res, ___)

# Negate the is.na function
is_not_na <- ___(___)

# Run is_not_na on the results
is_not_na(___)
编辑并运行代码