vec2tab: Vector to array conversion

View source: R/vec2tab.R

vec2tabR Documentation

Vector to array conversion

Description

Convert a vector into an array given a set of dimensions; it therefore simply wraps base::aperm() and base::array().

Usage

vec2tab(vec, dim)

Arguments

vec

A vector

dim

The desired array dimensions, oftentimes a vector of the number of levels of each variable in order

Details

This function converts an array (or a multi-way contingency table) into a vector, using a consistent ordering of the cells. The ordering of the cells is lexicographic and cannot be specified by the user.

Value

An array

See Also

tab2vec(), base::aperm(), base::array()

Examples


data(Titanic)
str( Titanic )
str( tab2vec(Titanic) )

# convert it back into a table (names are removed)
vec2tab(
  tab2vec(Titanic), 
  dim(Titanic)
)

# check that they are the same
all( vec2tab(tab2vec(Titanic), dim(Titanic)) == Titanic )



latte documentation built on June 9, 2025, 9:08 a.m.

Related to vec2tab in latte...