Skip to contents

This function reliably returns integer names if present, otherwise character dimnames. Use this instead of colnames() if you need guaranteed dispatch.

Usage

col_names(x)

# Default S3 method
col_names(x)

# S3 method for class 'matrix_int_names'
col_names(x)

col_names(x) <- value

# Default S3 method
col_names(x) <- value

# S3 method for class 'matrix_int_names'
col_names(x) <- value

Arguments

x

A matrix_int_names object

value

a vector of integer or character column names to set, replacing the current one.

Value

Integer or character vector of column names, or NULL

Examples

my_mat <- matrix_int_names(matrix(1:6, nrow = 2),
  row_names = c(10L, 20L),
  col_names = c(100L, 200L, 300L)
)
col_names(my_mat)
#> [1] 100 200 300
# set character names instead
col_names(my_mat) <- c("a", "b", "c")
col_names(my_mat)
#> [1] "a" "b" "c"