Changing data frame column headings
If you check, the help files, you will find rename in reshape and plyr, but not reshape2. But you have never shown us the command you used with names() and what didn't work:
a <- data.frame(alk_quant=rnorm(5, 5), ph_quant= rnorm(5, 5),
+ tds_quant=rnorm(5, 5))
a
alk_quant ph_quant tds_quant 1 6.569293 5.494560 5.521039 2 4.854873 5.612902 5.235817 3 4.636218 5.116499 5.973769 4 5.430009 6.273394 3.511017 5 5.714755 6.876349 4.035907
names(a) <- gsub("_quant", "", names(a))
a
alk ph tds 1 6.569293 5.494560 5.521039 2 4.854873 5.612902 5.235817 3 4.636218 5.116499 5.973769 4 5.430009 6.273394 3.511017 5 5.714755 6.876349 4.035907 ---------------------------------------------- David L Carlson Associate Professor of Anthropology Texas A&M University College Station, TX 77843-4352
-----Original Message----- From: r-help-bounces at r-project.org [mailto:r-help-bounces at r- project.org] On Behalf Of Rich Shepard Sent: Wednesday, December 05, 2012 3:25 PM To: R help 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.