[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,
F90:
JJ<-data.frame( c( as.character(rep( gender,3))) , c( F76,6- F83, F90) )
Looking into JJ one has:
c.as.character.rep.gender..8...
c.6...F73..F78..F79..F82..6...F84..F94..F106..F109
1 w 2
2 w 3
3 m 1
etc.
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.
hth
Wolfgang
More information about the R-help
mailing list