Learn R Programming

BBmisc (version 1.5)

rowLapply: Apply function to rows of a data frame.

Description

Just like an lapply on data frames, but on the rows.

Usage

rowLapply(df, fun, ..., unlist = FALSE)

rowSapply(df, fun, ..., unlist = FALSE, simplify = TRUE, use.names = TRUE)

Arguments

df
[data.frame] Data frame.
fun
[function] Function to apply. Rows are passed as list or vector, depending on argument unlist, as first argument.
...
[ANY] Additional arguments for fun.
unlist
[logical(1)] Unlist the row? Note that automatic conversion may be triggered for lists of mixed data types Default is FALSE.
simplify
[logical(1)] Should the result be simplified? See sapply. Default is TRUE.
use.names
[logical(1)] Should result be named by the row names of df? Default is TRUE.

Value

  • [list or simplified object]. Length is nrow(df).

Examples

Run this code
rowLapply(iris, function(x) x$Sepal.Length + x$Sepal.Width)

Run the code above in your browser using DataLab