combine: Combine lists by elements

Description Usage Arguments Value Examples

View source: R/combine.R

Description

Function returns a list combined by applying a function f pairwisely on i-th element of a list a and b, for each i. If a's (resp. b's) i-th element is NULL, the function f is not called and the result contains the b's (resp. a's) non-NULL element at the i-th position. The resulting list has size of the larger list, hence the elements of the shorter input lists are recycled to the size of the larger list. The elements are combined by index. Names of the elements are ignored.

Usage

1
combine(a, b, f = `+`)

Arguments

a

the first list to be combined

b

the second list to be combined

f

the function to be called pairwisely on the elements of a and b to produce the combined result

Value

an unnamed list of elements

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
combine(list(1, 2, 3), list(2, 4, 6), f=`+`)
# results in list(3, 6, 9)

combine(list(1, 2, 3), list(2, 4), f=`+`)
# results in list(3, 6, 3)

a <- list()
a[[3]] <- 10
b <- list()
a[[5]] <- 20
combine(a, b, f=`+`)
# results in list(NULL, NULL, 10, NULL, 20)

beerda/hexmatrix documentation built on May 2, 2021, 4:15 a.m.