[R] change column name in a function

Ott Toomet siim at obs.ee
Wed Jun 26 17:47:30 CEST 2002


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"


Cheers,

Ott

-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
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