doforeachrow: Applies a function to each row of a data frame

Description Usage Arguments Details Value Note Examples

View source: R/doforeachrow.r

Description

This function applies a function to each row of a data frame. All variables of the data frame and the optional arguments are passed as arguments to the function.

Usage

1
doforeachrow(data, fun, doitalsoforoptargs, ...)

Arguments

data

A data frame.

fun

A non-empty character string naming the function to be called.

doitalsoforoptargs

Logical. See Details.

...

Other arguments.

Details

It applies a function to each row of the data frame. The variables of the data frame and the optional arguments are passed as arguments. If there are common names among the data frame and the optional arguments, those values of the data frame are used.

If doitalsoforoptargs is TRUE, then try to use the row of the optional arguments, if it is possible (only when the length of the optional argument is equal to the number of rows of the data base). Otherwise, (doitalsoforoptargs = FALSE or the lengths are different), the whole optional arguments are passed to the function.

Value

A list for each row with the values returned by the function.

Note

Generic function.

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
fun <- "seq"
data <- data.frame(from=c(1,10), to=c(2,11))
doforeachrow(data, fun, TRUE)
## [[1]]
## [1] 1 2

## [[2]]
## [1] 10 11

doforeachrow(data, fun, TRUE, length.out=c(4))
## [[1]]
## [1] 1.000000 1.333333 1.666667 2.000000

## [[2]]
## [1] 10.00000 10.33333 10.66667 11.00000

doforeachrow(data, fun, TRUE, length.out=c(3,5))
## [[1]]
## [1] 1.0 1.5 2.0

## [[2]]
## [1] 10.00 10.25 10.50 10.75 11.00

xkcd documentation built on May 2, 2019, 4:47 p.m.