mapCols: Maps function onto each element of the specified columns

View source: R/watanabe-df-manipulation.R

mapColsR Documentation

Maps function onto each element of the specified columns

Description

Maps fun to each element of the the columns of df specified in .... Returns the original data frame with the values of specified columns updated with the values produced from mapping the function

Usage

mapCols(df, fun, cols = c(), ...)

Arguments

df

A dataframe.

fun

A function to apply to each element of the selected columns. Elements of these columns will be the first argument passed to this function.

cols

A vector containing the names (as strings) or index numbers of the columns with elements to which to apply fun.

...

Additional arguments to pass to fun

Value

A dataframe of the same dimensions as df with cols containing the results of applying fun to each element.

Details

mapCols works by folding over the set of columns to manipulate. For each column in cols, runs fun over its elements using sapply and replacing the column's original contents with the output.


awatanabe/appr documentation built on Sept. 26, 2022, 8:04 a.m.