[R] help: how to change the column name of data.frame
Prof Brian Ripley
ripley at stats.ox.ac.uk
Tue Jul 19 09:49:13 CEST 2005
Just change the names! E.g.
names(DF)[c(4,6)] <- names(DF)[c(6,4)]
Strictly a data frame has names, not column names, hence the use the
names() and names<-() functions here.
On Tue, 19 Jul 2005, wu sz wrote:
> I have a data frame with 15 variables, and want to exchange the data
> of 4th column and 6th column. First I append a column in the data
> frame, copy the 4th column data there, then copy the 6th column data
> to 4th column, and copy the appended column data to 6th column, but
> the names of the 4th and 6th column are still unchanged. How can I
> exchange them?
Brian D. Ripley, ripley at stats.ox.ac.uk
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, UK Fax: +44 1865 272595
More information about the R-help