Hi, Can someone please tell me how to change the column name of a specific column. How do I change the name of the column 'Species'? Thanks in advance d <- iris colnames(d) [1] "Sepal.Length" "Sepal.Width" "Petal.Length" "Petal.Width" "Species" ind <- which(names(d)=='Species') ind [1] 5 colnames(d[ind]) [1] "Species" colnames(d[ind]) <- 'new name' colnames(d[ind]) [1] "Species" -- View this message in context: http://r.789695.n4.nabble.com/changing-a-specific-column-name-tp3480739p3480739.html Sent from the R help mailing list archive at Nabble.com.
> colnames(d)[ind] <- 'new name' > colnames(d)[1] "Sepal.Length" "Sepal.Width" "Petal.Length" "Petal.Width" "new name" -----Original Message----- From: r-help-bounces at r-project.org [mailto:r-help-bounces at r-project.org] On Behalf Of pdb Sent: Thursday, April 28, 2011 7:39 AM To: r-help at r-project.org Subject: [R] changing a specific column name Hi, Can someone please tell me how to change the column name of a specific column. How do I change the name of the column 'Species'? Thanks in advance d <- iris colnames(d) [1] "Sepal.Length" "Sepal.Width" "Petal.Length" "Petal.Width" "Species" ind <- which(names(d)=='Species') ind [1] 5 colnames(d[ind]) [1] "Species" colnames(d[ind]) <- 'new name' colnames(d[ind]) [1] "Species" -- View this message in context: http://r.789695.n4.nabble.com/changing-a-specific-column-name-tp3480739p3480739.html Sent from the R help mailing list archive at Nabble.com. ______________________________________________ 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.
almost there, just use colnames(d)[ind] <- 'new name' (order of brackets matters) Am 28.04.2011 13:39, schrieb pdb:> Hi, > > Can someone please tell me how to change the column name of a specific > column. How do I change the name of the column 'Species'? > > Thanks in advance > > > d <- iris > > colnames(d) > [1] "Sepal.Length" "Sepal.Width" "Petal.Length" "Petal.Width" "Species" > > ind <- which(names(d)=='Species') > > ind > [1] 5 > > colnames(d[ind]) > [1] "Species" > > colnames(d[ind]) <- 'new name' > > colnames(d[ind]) > [1] "Species" > > -- > View this message in context: http://r.789695.n4.nabble.com/changing-a-specific-column-name-tp3480739p3480739.html > Sent from the R help mailing list archive at Nabble.com. > > ______________________________________________ > 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.-- Eik Vettorazzi Institut f?r Medizinische Biometrie und Epidemiologie Universit?tsklinikum Hamburg-Eppendorf Martinistr. 52 20246 Hamburg T ++49/40/7410-58243 F ++49/40/7410-57790