Apply a function to columns in a data.frame that inherit one of the specified types.

typly(
    data,
    f,
    types,
    negated = FALSE,
    ...
)

Arguments

data

A data.frame.

f

A function.

types

A character vector of classes to test against.

negated

Should the function be applied to columns that don't match any types? Defaults to FALSE.

...

Additional arguments to be passed to f.

Value

A list

Author

Alex Zajichek

Examples

heart_disease %>%
    
    #Compute means on numeric or logical data
    typly(
        f = mean,
        types = c("numeric", "logical"),
        na.rm = TRUE
    ) 
#> $Age
#> [1] 54.43894
#> 
#> $BP
#> [1] 131.6898
#> 
#> $Cholesterol
#> [1] 246.6931
#> 
#> $BloodSugar
#> [1] 0.1485149
#> 
#> $MaximumHR
#> [1] 149.6073
#>