Hi Rookie, Sure, just use the dimnames argument. You pass it a list where the first element contains the row names and the second element contains the column names. Supposing you only want to name one dimension, just use NULL for the other (see ?matrix for full details).
Using your data: x <- matrix(c(15, 7, 20, 12, 25, 14, 30, 19, 35, 7, 15, 7, 20, 17, 25, 19, 30, 25, 35, 10, 15, 15, 20, 12, 25, 19, 30, 22, 35, 11, 15, 11, 20, 18, 25, 18, 30, 19, 35, 15, 15, 9, 20, 18, 25, 18, 30, 23, 35, 11), nrow=25, byrow=TRUE, dimnames = list(NULL, c("Cotton", "Observations"))) Cheers, Josh On Tue, Aug 17, 2010 at 3:24 PM, Rookie <rookie8...@gmail.com> wrote: > Is there a way that I can specify the column names in the matrix function? > Currently, below is the way I am doing it. > > x <- matrix(c(15, 7, 20, 12, 25, 14, 30, 19, 35, 7, 15, 7, 20, 17, 25, 19, > 30, 25, 35, 10, 15, 15, 20, 12, 25, 19, 30, 22, 35, 11, 15, 11, 20, 18, 25, > 18, 30, 19, 35, 15, 15, 9, 20, 18, 25, 18, 30, 23, 35, 11), nrow=25, > byrow=TRUE) > colnames(x) <- c("Cotton", "Observations") > x > ______________________________________________ > R-help@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 Ph.D. Student, Health Psychology University of California, Los Angeles http://www.joshuawiley.com/ ______________________________________________ R-help@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.