描述統計與函式遮蔽(masking)
先前你已看到,summary() 會計算平均數、中位數、第 1 與第 3 四分位數,以及最小值與最大值,但不包含標準差。不過,Hmisc 與 psych 這兩個套件都提供 describe(),可以輸出更完整的描述統計,包括標準差。
為了取得這些描述統計,你將執行 describe()。因為兩個套件的函式同名,為了避免混淆,你應該使用 packagename::functionname() 這種寫法,明確指定要呼叫哪個套件裡的函式。
abaloneKeep 資料集與 dplyr 套件已為你載入。
本練習屬於課程
給 SAS 使用者的 R
練習說明
- 載入
Hmisc套件。 - 使用
Hmisc::describe()取得鮑魚的性別、length、diameter、height 的描述統計。 - 載入
psych套件——注意關於describe()自Hmisc套件被遮蔽的警告(因為兩個套件都有describe())。 - 使用
psych套件的describe()計算鮑魚的 length、diameter、height 的描述統計。不要包含性別,因為psych::describe()只適用於數值變數。
動手互動練習
試著完成這個範例程式碼,體驗一下這個練習。
# Load the Hmisc package
library(___)
# Run describe() from Hmisc for sex, length, diameter, height
abaloneKeep %>%
select(___, ___, ___, ___) %>%
___::___
# Load the psych package
___
# Run describe() from psych for length, diameter, height
___ %>%
___ %>%
___::___