MulaiMulai sekarang secara gratis

Descriptive statistics and function masking

Previously, you have seen that the summary() function computes the mean, median, 1st, and 3rd quartiles plus the min and max. The standard deviation is not included. However, the Hmisc and psych packages both have a describe() function that provide more descriptive statistics including the standard deviation.

To get these descriptive statistics, you will run the describe() function which has the same name in both packages. To avoid confusion, you should always use the notation packagename::functionname() to explicitly specify the function from the package you want.

The abaloneKeep dataset and dplyr package are already loaded for you.

Latihan ini adalah bagian dari kursus

R For SAS Users

Lihat Kursus

Petunjuk latihan

  • Load Hmisc package
  • Get descriptive stats for abalone sex, length, diameter, and height using Hmisc::describe() function.
  • Load psych package - notice the warnings about the describe() function masked from Hmisc package (since both packages have a describe() function).
  • Run describe() function from psych package to get descriptive stats for abalone length, diameter, height. Leave sex out since psych::describe() only works for numeric variables.

Latihan interaktif praktis

Cobalah latihan ini dengan menyelesaikan kode contoh berikut.

# 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
___ %>% 
  ___ %>% 
  ___::___
Edit dan Jalankan Kode