[R] change column names of several data frames
Henrik Parn
henrik.parn at bio.ntnu.no
Mon Apr 21 13:05:32 CEST 2008
Dear all,
I have several data frames for which I want to change the column names.
Example data:
data.1 <- data.frame(x1 = rnorm(5))
data.2 <- data.frame(x1 = rnorm(5))
.
.
What I want to achieve:
names(data.1) <- "y1"
names(data.1) <- "y1"
.
.
Is it possible to achieve this with a loop or any of the apply-functions?
Some (out of several...) unsuccessful attempts using for-loops instead:
for(i in 1:2)
names(get(paste("data", i, sep = "."))) <- "y1"
for(i in 1:2)
assign(paste("data", i, sep="."), names(get(paste("natal", i, sep =
"."))) <- "y1")
Thanks in advance!
/ Henrik Pärn
More information about the R-help
mailing list