I have a reshaped data frame with value column headings concatenated from two column headings in the melted data frame. I want to change all 56 headings in a single command, but 'names' allows me to change only one at a time. In Hadley's 2007 article on reshape in the Journal of Statistical Software he mentions a 'rename' function, but I cannot find that. Is there a way to change all data frame column headings in a single command? Rich
x <- data.frame(a = 1:5, b = rnorm(5)) names(x) <- LETTERS[2:1] print(x) seems to work. Can you be more explicit about your problem? Michael On Wed, Dec 5, 2012 at 6:51 PM, Rich Shepard <rshepard at appl-ecosys.com> wrote:> I have a reshaped data frame with value column headings concatenated from > two column headings in the melted data frame. I want to change all 56 > headings in a single command, but 'names' allows me to change only one at a > time. In Hadley's 2007 article on reshape in the Journal of Statistical > Software he mentions a 'rename' function, but I cannot find that. > > Is there a way to change all data frame column headings in a single > command? > > Rich > > ______________________________________________ > R-help at 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.
Hi, I am not sure why ?rename() is not working. ?a <- list(a = 1, b = 2, c = 3) ?? ? rename(a, c(b = "a", c = "b", a="c")) A.K. ----- Original Message ----- From: Rich Shepard <rshepard at appl-ecosys.com> To: r-help at r-project.org Cc: Sent: Wednesday, December 5, 2012 1:51 PM Subject: [R] Changing data frame column headings ? I have a reshaped data frame with value column headings concatenated from two column headings in the melted data frame. I want to change all 56 headings in a single command, but 'names' allows me to change only one at a time. In Hadley's 2007 article on reshape in the Journal of Statistical Software he mentions a 'rename' function, but I cannot find that. ? Is there a way to change all data frame column headings in a single command? Rich ______________________________________________ R-help at 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.
On Wed, 5 Dec 2012, arun wrote:> I am not sure why ?rename() is not working. > ?a <- list(a = 1, b = 2, c = 3) > ?? ? rename(a, c(b = "a", c = "b", a="c"))I have the reshape2 library loaded and ?rename did not find the help page. Are the parentheses required in the command? Thanks, Rich
Hi Rich, You can get ?rename() by either loading library(reshape) or library(plyr). A.K. ----- Original Message ----- From: Rich Shepard <rshepard at appl-ecosys.com> To: R help <r-help at r-project.org> Cc: Sent: Wednesday, December 5, 2012 4:24 PM Subject: Re: [R] Changing data frame column headings On Wed, 5 Dec 2012, arun wrote:> I am not sure why ?rename() is not working. > ?a <- list(a = 1, b = 2, c = 3) > ?? ? rename(a, c(b = "a", c = "b", a="c"))? I have the reshape2 library loaded and ?rename did not find the help page. Are the parentheses required in the command? Thanks, Rich ______________________________________________ R-help at 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.