[R] how to create column names for the matrix

lily li chocold12 at gmail.com
Wed Jul 27 20:17:46 CEST 2016


Hi all,

I want to ask that how to create column names for a matrix. For example,
the matrix below, the column names should be: 1-A, 1-B, 1-C, 1-D, 2-A, 2-B,
2-C, 2-D, 3-A, etc. Thanks for your help.

chars = c('A','B','C','D')
matrix1 = matrix(nrow = length(1:100), ncol = length(1:5)*length(chars))
k = 0
for(i in seq(1:length(1:5))){
  for(j in seq(1:length(chars))){
    k = k+1
    matrix1[,k] = c(1:100)[k]
  }
}

	[[alternative HTML version deleted]]



More information about the R-help mailing list