[R] defining columns in a matrix
Joshua Wiley
jwiley.psych at gmail.com
Sat Mar 13 00:20:29 CET 2010
Dear Kindra,
I think you are talking about...
matrix(1:9, nrow=3, dimnames=list(NULL, c("First","Second","Third")))
First Second Third
[1,] 1 4 7
[2,] 2 5 8
[3,] 3 6 9
If I am correct, what you are missing is that "dimnames" requires a
list with two elements, the rownames, and the colnames. As Ted
pointed out an alternate is to use colnames() on the matrix after you
have created it.
I hope that helps,
Josh
On Fri, Mar 12, 2010 at 2:29 PM, Kindra Martinenko
<kmartinenko at gmail.com> wrote:
> Hi all,
> I have the following 7 x 7 matrix. I am trying to figure out how to
> label the columns to something more descriptive other than [,1], [,2],
> etc.
> I have tried the c(x,y,z,) function, but I get a error returned
> stating that my vectors need to be the same length. Do I need to
> convert this to something else such as a list and then repack it?
>
> Thanks,
> Kindra
>
> Volume
> Time [,1] [,2] [,3] [,4] [,5] [,6] [,7]
> 17:00:00 7146 4926 5394 4534 6273 6192 6189
> 17:10:00 7227 4851 5414 4620 6026 7159 5878
> 17:20:00 7477 4678 5502 4298 6516 6469 5631
> 17:30:00 6533 4608 4813 4212 6083 5837 5657
> 17:40:00 6355 4669 5106 4242 5717 5635 5282
> 17:50:00 5657 4472 4545 3860 5378 4804 5304
> 18:00:00 5338 4508 4273 4024 4666 4597 5162
>
> ______________________________________________
> R-help at r-project.org 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.
>
--
Joshua Wiley
Senior in Psychology
University of California, Riverside
http://www.joshuawiley.com/
More information about the R-help
mailing list