df_apply | R Documentation |
Apply a function on each column of a data frame given a condition
df_apply(.data, .f, .condition = is.numeric, .else = identity, ...)
.data |
A data frame |
.f |
A function to apply on the data frame |
.condition |
Default value "is.numeric", but can be another data type |
.else |
Default value "identity" (skips over a column) |
... |
Any arguments from .f to pass |
A tibble
n <- 7L TestData <- tibble::tibble( double = rnorm(n, 100, 10), x = 123400 / 10^(1L:n), date = sample(seq(as.Date('1999/01/01'), as.Date('2022/01/01'), by="day"), n), integer = (1L:n) * (1L:n), # ^2 would return a double!! character = LETTERS[1L:n], factor = factor(letters[1L:n]), logical = rep(c(TRUE, FALSE), length.out = n) ) df_apply(TestData, round, is.numeric, digits =4) df_apply(TestData, mean, is.numeric) df_apply(TestData, lubridate::year, lubridate::is.Date) df_apply(TestData, toupper, is.character)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.