[R] Rename objects based on list

Wade Wall wade.wall at gmail.com
Sat Nov 15 19:33:56 CET 2008


Hi all,

I am trying to find a way to rename R objects with names pulled from a
vector of names.  For example, I have a data frame, my.data.frame, and
a list of names, my.names.  My.names is simply the column names of
my.data.frame.

I want save the histogram with the column name as the name of the object.

for (i in 1:ncol(my.data.frame) {
 tmp<-hist(my.data.frame[,i])
name(tmp)<-my.names[i] ##This is not real code, but what I want to do,
which is change the name of tmp to the name held at my.names[,i]
}

Basically, I am looking for a way to loop through columns in a data
frame, perform some function on the column, and name the output based
on the name of the column.

Thanks for any help.

Wade



More information about the R-help mailing list