Learn R Programming

BBmisc (version 1.13)

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)

Value

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

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) | character(1)]
Should the result be simplified? See sapply. If “cols”, we expect the call results to be vectors of the same length and they are arranged as the columns of the resulting matrix. If “rows”, likewise, but rows of the resulting matrix. Default is TRUE.

use.names

[logical(1)]
Should result be named by the row names of df? Default is TRUE.

Examples

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

Run the code above in your browser using DataLab