Class activity

Author

Your name

library(tidyverse)

example_df <- data.frame(
  x1 = c(1, 2, 3),
  x2 = c("a", "b", "c"),
  x3 = c(5, 1, 2),
  y1 = c(0, 9, 2),
  y2 = c(2, 7, 9),
  z = c(0, 0, 0)
)

example_df
  x1 x2 x3 y1 y2 z
1  1  a  5  0  2 0
2  2  b  1  9  7 0
3  3  c  2  2  9 0
example_df |>
  select(starts_with("x"))
  x1 x2 x3
1  1  a  5
2  2  b  1
3  3  c  2
example_df |>
  select(where(is.numeric))
  x1 x3 y1 y2 z
1  1  5  0  2 0
2  2  1  9  7 0
3  3  2  2  9 0
example_df |>
  select(where(is.numeric) & starts_with("x"))
  x1 x3
1  1  5
2  2  1
3  3  2
example_df |>
  summarize(across(where(is.numeric) & starts_with("x"), 
                   list("median" = median, "iqr" = IQR)))
  x1_median x1_iqr x3_median x3_iqr
1         2      1         2      2