ddply_helper | R Documentation |
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
.
ddply_helper(d, fun)
d |
A |
fun |
A function to apply to each column of |
A data.frame
or tibble
with the function applied to each column.
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)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.