bogdan romocea wrote:

Dear R users,

I need to rename the columns of a series of data frames. The names of
the data frames and those of the columns need to be pulled from some
vectors. I tried a couple of things but only got errors. What am I
missing?

#---create data frame
dframes <- c("a","b","c")
assign(dframes[2],data.frame(11:20,21:30))

#---rename the columns
cols <- c("one","two")


names(get(dframes[2])) <- cols

Error: couldn't find function "get<-"

It tells you that there is not function "get<-": you cannot assign into something you are calling with get()!



assign(dframes[2],data.frame(cols[1]=11:20,cols[2]=21:30))

Error: syntax error

Note the "[1]" in the name!



labels(get(dframes[2]))[[2]] <- cols

Same as above.


What you are really going to do is:


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


Uwe Ligges


Error: couldn't find function "labels<-"

I'm using R 2.0.0 on Windows XP.

Thank you,
b.

______________________________________________
[EMAIL PROTECTED] mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html

______________________________________________ [EMAIL PROTECTED] mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html

Reply via email to