Riffle: Interleaves Values Within Matrices or Vectors

Description Usage Arguments Details Value Author(s) References Examples

View source: R/Riffle.R

Description

Mimics some of the behavior of the Riffle function (http://reference.wolfram.com/mathematica/ref/Riffle.html) in Mathematica. For matrices, it interleaves the columns. For vectors, it interleaves differently according to whether the subsequent values are presented as separate values or whether they are grouped with c().

Usage

1

Arguments

...

The objects or values that need to be interleaved.

Details

It is expected that all matrices to be interleaved would have the same number of rows, though they may have differing numbers of columns. If they have differing numbers of columns, they are all made to conform to the same dimension before proceeding by recycling the existing columns.

Value

A vector or a matrix depending on the input. If one or more input objects is a matrix, the result will also be a matrix.

Author(s)

Ananda Mahto

References

http://stackoverflow.com/q/21347207/1270695

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
m1 <- matrix(1:9, nrow = 3, ncol = 3)
m2 <- matrix(letters[1:9], nrow = 3, ncol = 3)

Riffle(m1, m2)
Riffle(m1, "||", m2)

m3 <- matrix(LETTERS[1:6], nrow = 3, ncol = 2)

Riffle(m1, m2, m3)

## Just vectors

Riffle(1:6, "x")
Riffle(1:6, "x", "y")
Riffle(1:6, c("x", "y"))

mrdwab/SOfun documentation built on June 20, 2020, 6:15 p.m.