开始使用免费开始使用

使用谓词探索数据

我们将继续探索 A/B 测试数据。您的经理并不关心是「哪些」天达到了阈值,他想知道是否「每一天」都达到了阈值,或者是否「有些」天达到了阈值。我们将使用 purrr 的谓词函数来回答这些问题。

您收到了多个阈值,并决定编写一个脚本:从阈值定义开始,对每个设计判断是否所有天数都达到了阈值;如果没有,是否至少有部分天数达到了阈值。

此 A/B 测试的结果保存在 all_visits 列表中。

本练习是课程的一部分

使用 purrr 的函数式编程进阶

查看课程

练习说明

  • 创建名为 threshold 的变量,取值为 160。
  • 创建一个新的 mapper,用于测试 .x 是否大于 threshold
  • 结合使用 map()every() 来测试是否所有元素都超过阈值。
  • 结合使用 map()some() 来测试是否有部分元素超过阈值。

交互式实操练习

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

# Create a threshold variable, set it to 160


# Create a mapper that tests if .x is over the defined threshold
over_threshold <- ___(~ .x > ___)

# Are all elements in every all_visits vectors over the defined threshold? 
map(all_visits, ~ ___(.x, ___))

# Are some elements in every all_visits vectors over the defined threshold? 
map(all_visits, ~ ___(.x, ___))
编辑并运行代码