df_apply: Apply a function to a data frame

View source: R/df_apply.R

df_applyR Documentation

Apply a function to a data frame

Description

Apply a function to a data frame

Usage

df_apply(
  .data,
  .f,
  .condition = function(x) {     TRUE },
  .else = function(x) {     x },
  ...
)

Arguments

.data

A data frame

.f

A function you would like to apply to a column(s) of the data frame

.condition

A condition that column must have to apply the function

.else

If the condition fails, a second function to apply

...

Allows for arguments to be passed into .f

Value

A data frame

Examples

n <- 7L
TestData <-
 tibble::tibble( double = rnorm(n, 100, 10),
         x = 123400 / 10^(1L: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, toupper, digits = 1)

data(medals_per_event)
df_apply(medals_per_event, tolower, function(x){!is.numeric(x)})

sadleskorn/apply303 documentation built on April 14, 2022, 11:57 a.m.