[R] change column name in a function

Patrick Connolly p.connolly at hortresearch.co.nz
Wed Jun 26 23:03:17 CEST 2002

On Wed, 26-Jun-2002 at 05:47PM +0200, Ott Toomet wrote:

|> On Wed, 26 Jun 2002, Ulrich Leopold wrote:
|>   |Hi,
|>   |
|>   |I have the following function:
|>   |
|>   |TEST <- cbind(Pox0t30.stone.1990.2000, 
|>   |sqrt(apply(Pox0t30.stone.1990.2000[,2:11], 1, var)))
|>   |
|>   |In rhe resulting Object TEST the added column is titled:
|>   |sqrt(apply(Pox0t30.stone.1990.2000[,2:11], 1, var)
|>   |
|>   |I would like to change it to a sensible variable name like PoxMean. How 
|>   |can I incorporate this into the above function?
|> What do you mean with ,,function'' in the above?  But you may easily change
|> the names of the components of test.  Use the fact, that the variable names
|> in a data.frame (and in a matrix too) are store as the second component in
|> the list dimnames(TEST).  So you could try e.g.
|> dimnames(TEST)[[2]][length(dimnames(TEST)[[2]]) <- "PoxMean"

Or even simpler (if it is a dataframe),

names(TEST)[length(names(TEST))] <- "PoxMean"


Patrick Connolly
Mt Albert
New Zealand 
Ph: +64-9 815 4200 x 7188
I have the world`s largest collection of seashells. I keep it on all
the beaches of the world ... Perhaps you`ve seen it.  ---Steven Wright 

The contents of this e-mail are privileged and/or confidential to the
named recipient and are not to be used by any other person and/or
organisation. If you have received this e-mail in error, please notify 
the sender and delete all material pertaining to this e-mail.
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 mailing list