[R] renaming columns

About this list Date view Thread view Subject view Author view Other groups

Subject: [R] renaming columns
From: Marc Feldesman (feldesmanm@pdx.edu)
Date: Sun 25 Jun 2000 - 12:07:24 EST


Message-Id: <4.3.2.7.0.20000624185742.00abe730@pop4.ibm.net>

I frequently get data sets with cryptically-named variables. The datasets
are more useful to me with informative variable names. I know that I can
rename variables using the following command:

dimname(dataset[[2]][index.of.variable.to.be.renamed]<-new.variable.name

If I want to do this inside a function (say something I call RenameCol)
what is the best way to communicate the new.variable.name back to the
calling frame (e.g.)

RenameCol<-function(dframe, index, newname)
{
        #code to make certain there *are* dimnames
        dimname(dframe[[2]][index]<-newname
        invisible()
        return(dframe)
}

The above code works in both SPlus and R if the call looks like:

dframe<-RenameCol(dframe, 3, "a.new.name")

Is there a better way to return the new variable name without having to
make an explicit assignment at the time of calling RenameCol (i.e. can the
explicit assignment be made more efficiently within the function using
"Assign" or "<<-")?

Be gentle. Although I've used SPlus and now R for more than a year, I've
rarely needed to create functions that change specific attributes of an
object. (I also do not have VR Programming or VR3 at my disposal right now).

Thanks,

===================================================
Dr. Marc R. Feldesman
Professor and Chair
Anthropology Department
Portland State University
Portland, Oregon 97207

email: feldesmanm@pdx.edu
http://odin.pdx.edu/~h1mf

Powered by Inspirochoerus

"Indecision may or may not be my problem"
===================================================

-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
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@stat.math.ethz.ch
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._


About this list Date view Thread view Subject view Author view Other groups

This archive was generated by hypermail 2b25 : Mon 17 Jul 2000 - 12:33:24 EST