0

I have a simple 12 x 2 matrix called m that contains my dataset (see below).

Question

I was wondering why when I use dimnames(m) to create two names for the two columns of my data, I run into an Error? Is there a better way to create column names for this data in R?

Here is my R code:

Group1 = rnorm(6, 7)  ;  Group2 = rnorm(6, 9)
Level = gl(n = 2, k = 6)

m = matrix(c(Group1 , Group2, Level), nrow = 12, ncol = 2)
dimnames(m) <- list( DV = Group1, Level = Level)
Community
  • 1
  • 1
rnorouzian
  • 7,397
  • 5
  • 27
  • 72

1 Answers1

1

replace dimnames(m) with

colnames(m) <- c("DV","Level")
David Pedack
  • 482
  • 2
  • 10
  • So in text, what would the last column name look like? 'Level_1_12' or something like that? – David Pedack May 24 '17 at 22:19
  • I see what you mean. The way R works, the first column you are looking at is actually internal row numbers. They cannot have a column name assigned, because they're not actually part of the data set. – David Pedack May 24 '17 at 22:23
  • i don't think this works with a matrix, but it does with a data.frame. if this is just for presentation purposes, maybe convert to a data.frame before https://stackoverflow.com/questions/24428051/removing-display-of-r-row-names-from-data-frame – David Pedack May 24 '17 at 22:31