開始使用免費開始

使用 replace_with_na

延續上一個資料集,我們已經知道有一些奇怪的遺漏值表達方式。

現在要來處理它們,用 replace_with_na() 將這些值替換成標準的遺漏值(例如 NA)。

本練習屬於課程

在 R 中處理遺漏值

檢視課程

練習說明

針對 pacman 資料集:

  • 使用 replace_with_na(),把 yearscore 兩個變數中的 "N/A""na""missing" 這些遺漏值字樣替換為 NA
  • 最後用 miss_scan_count() 測試是否已經移除所有這類遺漏值。

動手互動練習

試著完成這個範例程式碼,體驗一下這個練習。

# Print the top of the pacman data using `head()`
head(___)

# Replace the strange missing values "N/A", "na", and  
# "missing" with `NA` for the variables, year, and score
pacman_clean <- replace_with_na(_____, replace = list(year = c(___, ___, ___),
                                score = c(___, ___, ___)))
                                        
# Test if `pacman_clean` still has these values in it?
miss_scan_count(____, search = list(___, ___, ___))
編輯並執行程式碼