[R] changing colnames in dataframes

Wolfgang Lindner LindnerW at t-online.de
Wed Dec 3 20:30:56 CET 2008

dear all,

I'm building new dataframes from bigger one's using e.g. columns F76, F83,

JJ<-data.frame( c( as.character(rep( gender,3))) , c( F76,6- F83, F90) )

Looking into JJ one has:

1                                     w                   2
2                                     w                   3
3                                     m                  1

Instead of the automatic colnames 'c.as.character.rep.gender..8' I like to
have the colnames 'gender' and 'J.value'.
I tried levels, labels etc but without success.

OK, I can fix(FF) manually, but this is bad, because it has to be done again
and again ..
OK, I can do

gender.J<-c( as.character(rep( gender,3)))
Jvalue<-c( F76,6- F83, F90)
JJ<-data.frame(gender.J, J.value)

but this is not optimal because 'gender' is depending on rep(.., n) and I
have many dataframes KK, LL, .. using 'gender' with different size.

Question: is it possible to do something like

JJ<-data.frame(c( as.character(rep( gender,3))),c( F76,6- F83, F90),  ??
col.names=c("gender","Jvalue") ?? )

Sorry, if my question is elementary, but I could not find a fix.

Thank your for your advice.



More information about the R-help mailing list