Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

naming columns and rows of an array (using 'dimnames =' argument in the syntax)

Tags:

r

how can we assign names to rows and columns of a array in R. below is what i tried using.

a<- array(1:50,dim = c(25,2),dimnames = list("Col1","col2"))

thanks

like image 405
KT11 Avatar asked Sep 19 '25 12:09

KT11


1 Answers

We need to specify the rownames and column names. Below, we are assuming the rownames to be NULL and the column names as 'Col1' and 'Col2'

out <- array(1:50,dim = c(25,2), dimnames = list(NULL, c("Col1", "Col2")))

According to ?array

dimnames: either ‘NULL’ or the names for the dimensions. This must a list (or it will be ignored) with one component for each dimension, either ‘NULL’ or a character vector of the length given by ‘dim’ for that dimension. The list can be named, and the list names will be used as names for the dimensions. If the list is shorter than the number of dimensions, it is extended by ‘NULL’s to the length required.

like image 191
akrun Avatar answered Sep 22 '25 17:09

akrun