[R] assign names to matrix
Pan_Yuming at aam.de
Thu Nov 16 17:52:42 CET 2000
Thanks for your advice.
My interest is to how to refer to each column as if it is a variable. i
solved this problem by
dimnames(v) <- list(1:nrow(v),label)
v <- as.data.frame(v)
now i can refer to column 1 of v as v$A...
Thomas Lumley <thomas at biostat.washington.edu> on 16.11.2000 17:11:25
To: Pan_Yuming at aam.de
cc: r-help at stat.math.ethz.ch
Subject: Re: [R] assign names to matrix
On Thu, 16 Nov 2000 Pan_Yuming at aam.de wrote:
> dear all,
> i have a matrix and i dont know how to assign names to this matrix.
> given v is 100x5 matrix, and label -> c("A","B","C","D","E")
> idealy, names(v) <- label, but it doesnt work for different length
> if dimnames(v) <- list(1:nrow(v),label), then names(v) return NULL
> any smart ways? thanks in advance.
Lists have names(). Matrices don't have names(). They have dimnames() (or
colnames() and rownames()). You want to use dimnames instead.
Assistant Professor, Biostatistics
University of Washington, Seattle
r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html
Send "info", "help", or "[un]subscribe"
(in the "body", not the subject !) To: r-help-request at stat.math.ethz.ch
More information about the R-help