計算 NA 的數量
現在你已經有更嚴格版本的狀態碼擷取器,我們要把它用在網址清單上。
這裡的目標是找出清單中哪些網站回傳的狀態碼不在 200 到 203 之間。為了達成這件事,我們會「翻轉」is.na() 函式,也就是把原本遇到遺漏值回傳 TRUE 的行為,改成回傳 FALSE。
工作環境中已提供 urls 向量與 strict_code() 函式。httr 與 purrr 已為你載入。
本練習屬於課程
使用 purrr 的 R 語言中級函式程式設計
練習說明
執行
strict_code(),套用在 urls 向量上。使用
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(___)