rowLapply {BBmisc}R Documentation

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)
## [[1]]
## [1] 8.6
## 
## [[2]]
## [1] 7.9
## 
## [[3]]
## [1] 7.9
## 
## [[4]]
## [1] 7.7
## 
## [[5]]
## [1] 8.6
## 
## [[6]]
## [1] 9.3
## 
## [[7]]
## [1] 8
## 
## [[8]]
## [1] 8.4
## 
## [[9]]
## [1] 7.3
## 
## [[10]]
## [1] 8
## 
## [[11]]
## [1] 9.1
## 
## [[12]]
## [1] 8.2
## 
## [[13]]
## [1] 7.8
## 
## [[14]]
## [1] 7.3
## 
## [[15]]
## [1] 9.8
## 
## [[16]]
## [1] 10.1
## 
## [[17]]
## [1] 9.3
## 
## [[18]]
## [1] 8.6
## 
## [[19]]
## [1] 9.5
## 
## [[20]]
## [1] 8.9
## 
## [[21]]
## [1] 8.8
## 
## [[22]]
## [1] 8.8
## 
## [[23]]
## [1] 8.2
## 
## [[24]]
## [1] 8.4
## 
## [[25]]
## [1] 8.2
## 
## [[26]]
## [1] 8
## 
## [[27]]
## [1] 8.4
## 
## [[28]]
## [1] 8.7
## 
## [[29]]
## [1] 8.6
## 
## [[30]]
## [1] 7.9
## 
## [[31]]
## [1] 7.9
## 
## [[32]]
## [1] 8.8
## 
## [[33]]
## [1] 9.3
## 
## [[34]]
## [1] 9.7
## 
## [[35]]
## [1] 8
## 
## [[36]]
## [1] 8.2
## 
## [[37]]
## [1] 9
## 
## [[38]]
## [1] 8.5
## 
## [[39]]
## [1] 7.4
## 
## [[40]]
## [1] 8.5
## 
## [[41]]
## [1] 8.5
## 
## [[42]]
## [1] 6.8
## 
## [[43]]
## [1] 7.6
## 
## [[44]]
## [1] 8.5
## 
## [[45]]
## [1] 8.9
## 
## [[46]]
## [1] 7.8
## 
## [[47]]
## [1] 8.9
## 
## [[48]]
## [1] 7.8
## 
## [[49]]
## [1] 9
## 
## [[50]]
## [1] 8.3
## 
## [[51]]
## [1] 10.2
## 
## [[52]]
## [1] 9.6
## 
## [[53]]
## [1] 10
## 
## [[54]]
## [1] 7.8
## 
## [[55]]
## [1] 9.3
## 
## [[56]]
## [1] 8.5
## 
## [[57]]
## [1] 9.6
## 
## [[58]]
## [1] 7.3
## 
## [[59]]
## [1] 9.5
## 
## [[60]]
## [1] 7.9
## 
## [[61]]
## [1] 7
## 
## [[62]]
## [1] 8.9
## 
## [[63]]
## [1] 8.2
## 
## [[64]]
## [1] 9
## 
## [[65]]
## [1] 8.5
## 
## [[66]]
## [1] 9.8
## 
## [[67]]
## [1] 8.6
## 
## [[68]]
## [1] 8.5
## 
## [[69]]
## [1] 8.4
## 
## [[70]]
## [1] 8.1
## 
## [[71]]
## [1] 9.1
## 
## [[72]]
## [1] 8.9
## 
## [[73]]
## [1] 8.8
## 
## [[74]]
## [1] 8.9
## 
## [[75]]
## [1] 9.3
## 
## [[76]]
## [1] 9.6
## 
## [[77]]
## [1] 9.6
## 
## [[78]]
## [1] 9.7
## 
## [[79]]
## [1] 8.9
## 
## [[80]]
## [1] 8.3
## 
## [[81]]
## [1] 7.9
## 
## [[82]]
## [1] 7.9
## 
## [[83]]
## [1] 8.5
## 
## [[84]]
## [1] 8.7
## 
## [[85]]
## [1] 8.4
## 
## [[86]]
## [1] 9.4
## 
## [[87]]
## [1] 9.8
## 
## [[88]]
## [1] 8.6
## 
## [[89]]
## [1] 8.6
## 
## [[90]]
## [1] 8
## 
## [[91]]
## [1] 8.1
## 
## [[92]]
## [1] 9.1
## 
## [[93]]
## [1] 8.4
## 
## [[94]]
## [1] 7.3
## 
## [[95]]
## [1] 8.3
## 
## [[96]]
## [1] 8.7
## 
## [[97]]
## [1] 8.6
## 
## [[98]]
## [1] 9.1
## 
## [[99]]
## [1] 7.6
## 
## [[100]]
## [1] 8.5
## 
## [[101]]
## [1] 9.6
## 
## [[102]]
## [1] 8.5
## 
## [[103]]
## [1] 10.1
## 
## [[104]]
## [1] 9.2
## 
## [[105]]
## [1] 9.5
## 
## [[106]]
## [1] 10.6
## 
## [[107]]
## [1] 7.4
## 
## [[108]]
## [1] 10.2
## 
## [[109]]
## [1] 9.2
## 
## [[110]]
## [1] 10.8
## 
## [[111]]
## [1] 9.7
## 
## [[112]]
## [1] 9.1
## 
## [[113]]
## [1] 9.8
## 
## [[114]]
## [1] 8.2
## 
## [[115]]
## [1] 8.6
## 
## [[116]]
## [1] 9.6
## 
## [[117]]
## [1] 9.5
## 
## [[118]]
## [1] 11.5
## 
## [[119]]
## [1] 10.3
## 
## [[120]]
## [1] 8.2
## 
## [[121]]
## [1] 10.1
## 
## [[122]]
## [1] 8.4
## 
## [[123]]
## [1] 10.5
## 
## [[124]]
## [1] 9
## 
## [[125]]
## [1] 10
## 
## [[126]]
## [1] 10.4
## 
## [[127]]
## [1] 9
## 
## [[128]]
## [1] 9.1
## 
## [[129]]
## [1] 9.2
## 
## [[130]]
## [1] 10.2
## 
## [[131]]
## [1] 10.2
## 
## [[132]]
## [1] 11.7
## 
## [[133]]
## [1] 9.2
## 
## [[134]]
## [1] 9.1
## 
## [[135]]
## [1] 8.7
## 
## [[136]]
## [1] 10.7
## 
## [[137]]
## [1] 9.7
## 
## [[138]]
## [1] 9.5
## 
## [[139]]
## [1] 9
## 
## [[140]]
## [1] 10
## 
## [[141]]
## [1] 9.8
## 
## [[142]]
## [1] 10
## 
## [[143]]
## [1] 8.5
## 
## [[144]]
## [1] 10
## 
## [[145]]
## [1] 10
## 
## [[146]]
## [1] 9.7
## 
## [[147]]
## [1] 8.8
## 
## [[148]]
## [1] 9.5
## 
## [[149]]
## [1] 9.6
## 
## [[150]]
## [1] 8.9

[Package BBmisc version 1.7 Index]