identize_byname {matsbyname}R Documentation

Named identity matrix or vector

Description

Creates an identity matrix (I) or vector (i) of same size and with same names and same row and column types as a.

Usage

identize_byname(a, margin = c(1, 2))

Arguments

a

the matrix whose names and dimensions are to be preserved in an identity matrix or vector

margin

determines whether an identity vector or matrix is returned. See details.

Details

Behaviour for different values of margin are as follows:

Value

An identity matrix or vector.

Examples

M <- matrix(1:16, ncol = 4, dimnames=list(c(paste0("i", 1:4)), paste0("c", 1:4))) %>%
  setrowtype("Industries") %>% setcoltype("Commodities")
identize_byname(M)
identize_byname(M, margin = c(1,2))
identize_byname(M, margin = 1)
identize_byname(M, margin = 2)
N <- matrix(c(-21, -12, -21, -10), ncol = 2, dimnames = list(c("b", "a"), c("b", "a"))) %>%
  setrowtype("Industries") %>% setcoltype("Commodities")
identize_byname(N)
# This also works with lists
identize_byname(list(M, M))

[Package matsbyname version 0.6.10 Index]