expandcolumns: expandcolumns inserts missing matrix columns where colnames...

View source: R/rutils.R

expandcolumnsR Documentation

expandcolumns inserts missing matrix columns where colnames are numbers

Description

expandcolumns takes in a matrix that has column names that are numbers. These might be years or some other integers. If there are years missing this function will insert them into a larger matrix which is then returned.

Usage

expandcolumns(x)

Arguments

x

a matrix with integers as column names. This might be a series of counts at size for a series of years or counts at age for a number of years. If some years of data are missing this function will insert empty columns into a larger matrix so that when plotted a true view of available data can be presented. If there are no missing years then the original matrix is returned.

Value

a matrix with integers (years) as column names is returned with no missing years, even where some years have no data.

Examples

dat <- matrix(trunc(rnorm(50, mean=20, sd=4)),nrow=10,ncol=5,
              dimnames=list(1:10,c(1990,1991,1995,1997,1999)))
print(dat)
print(expandcolumns(dat))               

haddonm/codeutils documentation built on April 15, 2024, 1:02 p.m.