Package 'interleave'

Title: Converts Tabular Data to Interleaved Vectors
Description: Converts matrices and lists of matrices into a single vector by interleaving their values. That is, each element of the result vector is filled from the input matrices one row at a time. This is the same as transposing a matrix, then removing the dimension attribute, but is designed to operate on matrices in nested list structures.
Authors: David Cooley [aut, cre], Mapbox [cph] (author of header library earcut.hpp)
Maintainer: David Cooley <[email protected]>
License: MIT + file LICENSE
Version: 0.1.2
Built: 2024-10-14 06:21:12 UTC
Source: CRAN

Help Index


Interleave

Description

Converts matrices and lists of matrices into a vector. The elements of the vector are taken from the matrices one row at a time.

Usage

interleave(x)

Arguments

x

object to interleave

Value

vector of interleaved values

Examples

## matrix (this is equivalent to a LINESTRING in spatial structures)
m1 <- matrix(1:20, ncol = 2, byrow = TRUE )
interleave( m1 )

## This is the same as transposing and removing the 'dim' attribute
tm <- t(m1)
attr( tm, "dim" ) <- NULL
all( interleave( m1 ) == tm )

## list of matrices (this is equivalent to a POLYGON in spatial structures)
m2 <- matrix(20:1, ncol = 2, byrow = TRUE )
l <- list( m1, m2 )
interleave( l )

## nested list of matrices
l <- list( m1, list( list( m2 ) ) )
interleave( l )