[R] Matrix dimnames

Daniel Gatti dmgatti at email.unc.edu
Wed Nov 1 23:26:37 CET 2006


R version : 2.4.0
O/S: Windows XP SP2 :-(

How does one assign names to the columns of a matrix so that the columns 
can be accesses using the '$' operator? It seem that x$c1 below should 
return column 1.

 > x = matrix(1:4,2)
 > dimnames(x) = list(c("r1", "r2"), c("c1", "c2"))
 > x
    c1 c2
r1  1  3
r2  2  4
 > x$c1
NULL
 > x$c2
NULL

Daniel Gatti
UNC-CH



More information about the R-help mailing list