[R] Define column names to a series of data.frames

Nikos Alexandris nikos.alexandris at felis.uni-freiburg.de
Thu Mar 11 13:33:33 CET 2010


Greets to the list!

I am aware that this topic has been discussed several times. And I've
read quite some related posts [1]. Yet, can't seem to give a solution to
my problem.

I have 6 data frames consisting of 6 rows x 7 columns put together from
other data.frames.

Something like:

   a b c d e f g
v1 # # # # # # # 
v2 # # # # # # #
v3 # # # # # # #
v4 # # # # # # #
v5 # # # # # # #
v6 # # # # # # #


I want to give the following column names to each data.frame: ("SDev",
"PC1", "PC2", "PC3", "PC4", "PC5", "PC6")

Works fine for one data.frame:
column_names <- c("SDev", "PC1", "PC2", "PC3", "PC4", "PC5", "PC6")
names( df1 ) <- column_names

How is it to be done at once for all data.frames that the function
objects(pattern = "SomePattern") can find?

I've tried several things with assign, get, paste, for but I am not
getting anywhere. I need to integrate this in a function that can handle
lot's of data.frames and not only 6.

Thank you, Nikos


---
[1] I am stuck on this post:
<http://www.mail-archive.com/r-help@stat.math.ethz.ch/msg32063.html>. 

It reads:

dframes <- c("a","b","c")
cols <- c("one","two")
df <- data.frame(11:20, 21:30)
names(df) <- cols
assign(dframes[2], df)

Can't understand the logic behind the "[2]".



More information about the R-help mailing list