MulaiMulai sekarang secara gratis

Specific statistics for one or more variables

As you saw before, you can use functions like summary(), psych::describe() or Hmisc::describe() to get many descriptive statistics at once for one or more variables in a dataset. You've also computed individual statistics in earlier exercises using functions like mean(), median(), sd() and others.

However, the dplyr package provides the summarise() function alone or by adding across(everything(), list()) syntax for multiple custom statistics of interest together for one or more variables at a time.

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

  • Get summary statistics for shucked weight and whole weight from the abaloneKeep dataset using summary().
  • Get mean and standard deviation of length using the summarise() function from the dplyr package. Name the output statistics mean_length and sd_length for mean and standard deviation respectively.
  • Get mean and standard deviation of height and diameter using the summarise(across(everything(), list())) syntax from the dplyr package.

Latihan interaktif praktis

Cobalah latihan ini dengan menyelesaikan kode contoh berikut.

# Run summary() for shuckedWeight and wholeWeight
abaloneKeep %>%
  select(___, ___) %>%
  ___

# Get mean and sd for length
abaloneKeep %>%
  ___(___ = mean(___),
      ___ = sd(___))

# Get mean and sd for height and diameter
abaloneKeep %>%
  ___ %>%
  summarise(across(everything(),list(___ = ~ mean(.x),
                                     ___ = ~ sd(.x))))
Edit dan Jalankan Kode