開始使用免費開始

建立 shadow matrix 資料

遺漏值常常不容易察覺,因為它們不會主動顯示,反而藏在資料的角落裡。

一個能幫助你發現遺漏值的方法,是改變看待資料的方式——把每個資料值都視為「遺漏」或「不遺漏」。

R 中的 as_shadow() 會把一個 dataframe 轉換成 shadow matrix。這是一種特殊的資料格式,其中的值只表示是否遺漏:遺漏(NA)或不遺漏(!NA)。

shadow matrix 的欄位名稱與原始資料相同,但都會加上 _NA 字尾。

若要同時追蹤並將原始資料值與其遺漏狀態對照,請使用 bind_shadow()。當我們把 shadow matrix 的欄位與原始資料綁在一起使用時,這種格式稱為 nabular 資料。

本練習屬於課程

在 R 中處理遺漏值

檢視課程

練習說明

使用 oceanbuoys 資料集:

  • 使用 as_shadow() 建立 shadow matrix 資料。
  • 使用 bind_shadow() 將 shadow 與原始資料綁在一起,建立 nabular 資料。
  • 只綁定包含遺漏值的變數:使用 bind_shadow(only_miss = TRUE)

動手互動練習

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

# Create shadow matrix data with `as_shadow()`
___(___)

# Create nabular data by binding the shadow to the data with `bind_shadow()`
___(___)

# Bind only the variables with missing values by using bind_shadow(only_miss = TRUE)
___(___, ___ = TRUE)
編輯並執行程式碼