df_apply | R Documentation |
Apply a function to qualifying columns in a data frame, a different function otherwise
df_apply(.data, .f, .condition = is.numeric, .else = identity, ...)
.data |
Data frame containing columns to apply functions to |
.f |
Function to apply to columns that fit .condition() |
.condition |
Condition to check to apply .f() |
.else |
Function to apply to columns that do NOT fit .condition() |
... |
Additional arguments to be passed to .f() |
A Data frame with the columns changed as specified.
n <- 7L test_data <- dplyr::tibble( double = rnorm(n, 100, 10), integer = (1L:n) * (1L:n), character = LETTERS[1L:n], factor = factor(letters[1L:n]), logical = rep(c(TRUE, FALSE), length.out = n) ) test_data df_apply(test_data, round, digits = -1) test_data |> df_apply(mean, is.numeric) test_data |> df_apply(tolower, is.character) test_data |> df_apply(round, is.numeric, as.factor, digits = -1)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.