[R] renaming columns

Marc Feldesman feldesmanm at pdx.edu
Sun Jun 25 04:07:24 CEST 2000


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



More information about the R-help mailing list