開始使用免費開始

用述詞(predicate)探索資料

我們要繼續探索 A/B 測試的資料。你的主管不在意是哪些天達到門檻,他想知道是否「每一天」都達到門檻,或是「有些」天達到門檻。我們會用 purrr 的述詞函式來回答這些問題。

你收到了好幾個門檻值,並決定寫一段指令稿:先從門檻值的定義開始,然後針對每個設計(design)回答是否所有天數都達到門檻;若沒有,是否有部分天數達到。

這次 A/B 測試的結果已存於 all_visits 清單。

本練習屬於課程

使用 purrr 的 R 語言中級函式程式設計

檢視課程

練習說明

  • 建立名為 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, ___))
編輯並執行程式碼