nrow_byname {matsbyname}R Documentation

Get the number of rows in a "byname" matrix.

Description

The function gets the number of rows in a "byname" matrix, or for each "byname" matrix contained in a column of a data frame.

Usage

nrow_byname(a)

Arguments

a

A matrix or a column of a data frame populated with "byname" matrices.

Value

The number of rows of the matrix, or a list containing the number of rows in each of the matrices contained in the column of a data frame.

Examples

productnames <- c("p1", "p2")
industrynames <- c("i1", "i2")
U <- matrix(1:4, ncol = 2, dimnames = list(productnames, industrynames)) %>% 
  setrowtype("Products") %>% 
  setcoltype("Industries")
productnames <- c("p1", "p2")
industrynames <- c("i1", "i2", "i3")
U2 <- matrix(1:3, ncol = length(industrynames), 
             nrow = length(productnames), dimnames = list(productnames, industrynames)) %>% 
  setrowtype("Products") %>% 
  setcoltype("Industries")
productnames <- c("p1", "p2", "p3")
industrynames <- c("i1", "i2", "i3", "i4")
U3 <- matrix(1:4, ncol = length(industrynames), 
             nrow = length(productnames), dimnames = list(productnames, industrynames)) %>% 
  setrowtype("Products") %>% 
  setcoltype("Industries")
dfUs <- data.frame(
  year = numeric(),
  matrix_byname = I(list())
)
dfUs[[1, "matrix_byname"]] <- U
dfUs[[2, "matrix_byname"]] <- U2
dfUs[[3, "matrix_byname"]] <- U3
dfUs[[1, "year"]] <- 2000
dfUs[[2, "year"]] <- 2001
dfUs[[3, "year"]] <- 2002
number_rows <- matsbyname::nrow_byname(dfUs$matrix_byname)

[Package matsbyname version 0.6.10 Index]