cumapply_byname: Apply a function cumulatively to a list of matrices or...

View source: R/Apply.R

cumapply_bynameR Documentation

Apply a function cumulatively to a list of matrices or numbers

Description

FUN must be a binary function that also accepts a single argument. The result is a list with first element FUN(a[[1]]). For i >= 2, elements are FUN(a[[i]], out[[i-1]]), where out is the result list.

Usage

cumapply_byname(FUN, a)

Arguments

FUN

the function to be applied

a

the list of matrices or numbers to which FUN will be applied cumulatively

Details

naryapply_byname() and cumapply_byname() are similar. Their differences can be described by considering a data frame. naryapply_byname() applies FUN to several columns (variables) of the data frame. For example, sum_byname() applied to several variables gives another column containing the sums across each row of the data frame. cumapply_byname() applies FUN to successive entries in a single column. For example sum_byname() applied to a single column gives the sum of all numbers in that column.

Value

a list of same length as a containing the cumulative application of FUN to a

Examples

cumapply_byname(sum, list(1, 2, 3, 4))
cumapply_byname(sum_byname, list(1, 2, 3, 4))
cumapply_byname(prod, list(1, 2, 3, 4))
cumapply_byname(hadamardproduct_byname, list(1, 2, 3, 4))

matsbyname documentation built on Oct. 19, 2023, 5:11 p.m.