insert_matrix_column {oeli}R Documentation

Insert column in matrix

Description

This function inserts a column into a matrix.

Usage

insert_matrix_column(A, x, p)

Arguments

A

A matrix.

x

A vector of length nrow(A), the column to be added.

Can also be a single value.

p

An integer, the position where to add the column:

  • p = 0 appends the column left

  • p = ncol(A) appends the column right

  • p = n inserts the column between the n-th and (n + 1)-th column of A.

Can also be a vector of multiple positions.

Value

A matrix.

Examples

A <- diag(3)
x <- 1:3
insert_matrix_column(A, x, 0)
insert_matrix_column(A, x, 1)
insert_matrix_column(A, x, 2)
insert_matrix_column(A, x, 3)

### also single value
x <- 2
insert_matrix_column(A, x, 0)

### also multiple positions
insert_matrix_column(A, x, 0:3)

### also trivial case
insert_matrix_column(matrix(nrow = 0, ncol = 0), integer(), integer())

[Package oeli version 0.5.2 Index]