Become an expert in R — Interactive courses, Cheat Sheets, certificates and more!
Get Started for Free

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) | 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.

Value

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

Examples

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

BBmisc

Miscellaneous Helper Functions for B. Bischl

v1.11
BSD_2_clause + file LICENSE
Authors
Bernd Bischl [aut, cre], Michel Lang [aut], Jakob Bossek [aut], Daniel Horn [aut], Jakob Richter [aut], Dirk Surmann [aut]
Initial release

We don't support your browser anymore

Please choose more modern alternatives, such as Google Chrome or Mozilla Firefox.