insertmissingRC: insertmissingRC inserts missing row and columns, which must...

View source: R/rutils.R

insertmissingRCR Documentation

insertmissingRC inserts missing row and columns, which must be numbers

Description

insertmissingRC takes in a matrix that has row and column names that are ordered integers These might be years, size classes, or some other integers, but they must be in ascending order. If there are rows or columns missing this function will insert them into a larger matrix which is then returned. The default increment for the row and column names is 1, but the option is there to change this if needed. If non-numeric row or column names occur a fatal error is called and the function stops with a message.

Usage

insertmissingRC(x, inccol = 1, incrow = 1)

Arguments

x

a matrix with ordered integers as row and column names. If some years (cols) or size-classes (rows) of data are missing this function will insert empty rows and/or columns into a larger matrix so that when plotted a true view of available data can be presented that illustrates what data is missing from the series. If there are no missing rows or columns then the original matrix is returned.

inccol

the increment used in the sequence of column names, default=1

incrow

the increment used in the sequence of row names, default=1

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(c(2,4,6,8,14,16,18,20,24,26),
              c("1990","1991","1995","1997","1999")))
print(dat)
print(insertmissingRC(dat,inccol=1,incrow=2))               
dat <- matrix(trunc(rnorm(50, mean=20, sd=4)),nrow=10,ncol=5,
dimnames=list(c(2,4,6,8,14,16,18,20,24,26),
              c("1990","1991A","1995","1997","1999")))
# running  insertmissingRC(dat,incrow=2) would throw an eror

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