ddply_helper {zmisc} | R Documentation |
Apply a function to each column of a data.frame
Description
Thin wrapper around lapply()
that checks that the input is a table before
applying the function to each column, and converts the result back to a table
afterwards. If the tibble
package is available and the input is a tibble
,
the result will be a tibble
; otherwise, it will be a plain data.frame
.
Usage
ddply_helper(d, fun)
Arguments
d |
A |
fun |
A function to apply to each column of |
Value
A data.frame
or tibble
with the function applied to each column.
Examples
df <- data.frame(
col1 = c(1, 2, 3),
col2 = c(4, 5, 6)
)
sum_fun <- function(x) sum(x)
result <- ddply_helper(df, sum_fun)
print(result)
[Package zmisc version 0.2.3 Index]