描述統計輸出
到目前為止,你只把輸出印到主控台。在這個練習中,你要把來自 summary() 與 psych::describe() 兩個函式、針對鮑魚重量測量的描述統計輸出儲存起來。
首先,你會儲存 summary() 函式的輸出,這是一個 table 類別的物件。table 物件中的元素可以用 [row, col] 語法來選取。
接著你會儲存 psych::describe() 的輸出。這個輸出是名為 psych describe 的自訂類別,同時也屬於 data.frame 類別。因此,可以用 $ 運算子,依名稱從這個輸出中擷取 psych::describe() 的元素。
abaloneKeep 資料集,以及 dplyr 與 psych 套件都已為你載入。
本練習屬於課程
給 SAS 使用者的 R
練習說明
- 將
abaloneKeep中 whole weight、shucked weight 和 shell weight 的摘要統計儲存為absummary。 - 顯示
absummary的第 1 到第 2 欄。 - 使用
psych::describe()取得abaloneKeep中 abalone whole weight、shucked weight 與 shell weight 的描述統計,並將輸出儲存為abpsych。 - 顯示
abpsych中的平均絕對離差mad。
動手互動練習
試著完成這個範例程式碼,體驗一下這個練習。
# Save summary stats output for 3 requested weights
absummary <- ___ %>%
select(___) %>%
___
# Pull columns 1 to 2 out of absummary
absummary[,___]
# Save describe from psych output for weights as abpsych
abpsych <- ___ %>%
___ %>%
___
# Display the mad element from abpsych
___