找出遺漏的觀測值
你是在核電廠工作的稽核員,需要驗證在整整 1 年期間,每座反應爐是否每天都完成安全檢查。安全檢查紀錄存於 reactor_df,這是一個包含 date、reactor 和 check 欄位的資料框。
已為你建立兩個向量 dates 與 reactors,分別包含全年所有日期與電廠內的所有反應爐。
你將使用 expand_grid() 搭配 anti_join() 的組合,找出特定反應爐在某些日期沒有被檢查的情況。
dplyr 套件已為你預先載入。
本練習屬於課程
使用 tidyr 重塑資料
練習說明
- 使用
expand_grid()建立一個包含date與reactor這兩個變數所有組合的 tibble。請使用已為你建立的dates與reactors向量。 - 以
date與reactor兩個欄位,對full_df和reactor_df進行 anti-join。
動手互動練習
試著完成這個範例程式碼,體驗一下這個練習。
# Create a tibble with all combinations of dates and reactors
full_df <- ___
# Find the reactor - date combinations not present in reactor_df
full_df %>%
___