naw3 at duke.edu
2008-Jul-01 19:17 UTC
[R] Change name of a specific column of a data frame
Hi, Sorry for the simple question. Is there a way to change the name of only one column of an existing data frame? I know colnames allows you to set the name of all the columns, but only one column in the middle of my data frame needs a new name. Thanks, -Nina
> x <- data.frame(a=1,b=2,c=3) > xa b c 1 1 2 3> colnames(x)[2] <- "done" > xa done c 1 1 2 3>On Tue, Jul 1, 2008 at 3:17 PM, <naw3 at duke.edu> wrote:> Hi, > > Sorry for the simple question. Is there a way to change the name of only one > column of an existing data frame? > > I know colnames allows you to set the name of all the columns, but only one > column in the middle of my data frame needs a new name. > > Thanks, > -Nina > > ______________________________________________ > 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. >-- Jim Holtman Cincinnati, OH +1 513 646 9390 What is the problem you are trying to solve?
Philip Twumasi-Ankrah
2008-Jul-01 19:32 UTC
[R] Change name of a specific column of a data frame
Try require(gregmisc) rename(data, from="old_name", to="new_name") A Smile costs Nothing But Rewards Everything Happiness is not perfected until it is shared -Jane Porter --- On Tue, 7/1/08, naw3@duke.edu <naw3@duke.edu> wrote: From: naw3@duke.edu <naw3@duke.edu> Subject: [R] Change name of a specific column of a data frame To: R-help@r-project.org Date: Tuesday, July 1, 2008, 2:17 PM Hi, Sorry for the simple question. Is there a way to change the name of only one column of an existing data frame? I know colnames allows you to set the name of all the columns, but only one column in the middle of my data frame needs a new name. Thanks, -Nina ______________________________________________ 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. [[alternative HTML version deleted]]
Leandro Marino
2008-Jul-01 19:36 UTC
[R] RES: Change name of a specific column of a data frame
You can use names(database)[position] where position is the number of the column that you want to rename! Leandro Marino -----Mensagem original----- De: r-help-bounces em r-project.org [mailto:r-help-bounces em r-project.org]Em nome de naw3 em duke.edu Enviada em: terca-feira, 1 de julho de 2008 16:18 Para: R-help em r-project.org Assunto: [R] Change name of a specific column of a data frame Hi, Sorry for the simple question. Is there a way to change the name of only one column of an existing data frame? I know colnames allows you to set the name of all the columns, but only one column in the middle of my data frame needs a new name. Thanks, -Nina ______________________________________________ R-help em 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.