Re: [R] changing colnames in dataframes
thank you all, Jagat, Bert and Prof. Ripley for your kind help. The PROBLEM was: give descripitve names to the columns in JJ-data.frame( c( as.character(rep( gender,3))) , c( F76,6- F83, F90) ) Possible SOLUTIONs are: 1.JJ - data.frame( gender=c( as.character(rep( gender,3))) , J.value=c(F76,6- F83, F90) ) 2. names(JJ) - c(gender,J.value) Now I can continue my work being happy with R. hth Wolfgang __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] changing colnames in dataframes
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 __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] changing colnames in dataframes
See the help page. You name the arguments, e.g. JJ - data.frame( gender= c( as.character(rep( gender,3))) , J.value -c( F76 ,6-F83, F90) ) The help says Arguments: ...: these arguments are of either the form 'value' or 'tag = value'. Component names are created based on the tag (if present) or the deparsed argument itself. On Wed, 3 Dec 2008, Wolfgang Lindner wrote: 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 -- Brian D. Ripley, [EMAIL PROTECTED] Professor of Applied Statistics, http://www.stats.ox.ac.uk/~ripley/ University of Oxford, Tel: +44 1865 272861 (self) 1 South Parks Road, +44 1865 272866 (PA) Oxford OX1 3TG, UKFax: +44 1865 272595 __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.