[R] dynamically naming columns in a data frame

Jarred McCaffrey jmccaffr at cs.uml.edu
Thu Sep 14 15:24:49 CEST 2000


Hello All!

I have been working with R for the last couple of weeks and I am very
impressed with the capabilities.  I am creating hundreds of tables and
need to dynamically name the columns.

Here is a small snippet of my code:

# Turn my clustering data into a data.frame object.
    names( clusters ) <- Abbreviate( distMethods[ i ], hclustMethods[ j
] )
    df <- data.frame( clusters, row.names = NULL, check.rows = FALSE,
check.names = TRUE )

If the formatting turned out properly, you should only see three lines
above, beginning with #, names, and df.

Abbreviate() returns a variable that contains a string (my
abbreviation).  Using names() like this does not change the column name
in the final csv output.

This does work:

df <- data.frame( newName=clusters, .... )

But newName is always read as a text string, I have not been able to
substitute a variable.  I also tried substituting the Abbreviate() call
for newName, hoping the char string return would be used.  That caused
syntax errors.

Does anyone know a solution to dynamically naming columns?

Thank you very much!

Jarred McCaffrey
jarred at acm.org

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