Hi Lorenzo, The problem is that my_matrix does not have dimnames. See below.
my_matrix <- matrix (1:12,ncol=3) str(my_matrix) ## does not have dimnames dimnames(my_matrix) ## dimnames is NULL colnames(my_matrix) <- "myname" # fails because you are trying to alter the value of something that does not exist ## solution: Set colnames colnames(my_matrix) <- 1:dim(my_matrix)[2] str(my_matrix) # my_matrix now has colnames colnames(my_matrix)[1] <- "myname" # and now we can alter them On Mon, Sep 27, 2010 at 8:26 AM, Lorenzo Cattarino <[email protected]> wrote: > Hi R-users > > > > I can not change the name of one column only of my matrix. > > > > my_matrix <- matrix (1:12,ncol=3) > > > > colnames(my_matrix)[1] <- 'myname' > > > > Error in dimnames(x) <- dn : > > length of 'dimnames' [2] not equal to array extent > > > > thank you for your help > > > > Lorenzo > > > [[alternative HTML version deleted]] > > ______________________________________________ > [email protected] mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code. > -- Ista Zahn Graduate student University of Rochester Department of Clinical and Social Psychology http://yourpsyche.org ______________________________________________ [email protected] mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.

