I am trying to rename the column names of a data frame called "data". It has 177 columns. I have used : colnames(data) <- a where a is a vector with 177 character names. I don''t get any error message, but the column names don''t change because when I then type : colnames(data) I get the same set of names as before, so the assignment doesnt seem to have worked. Any ideas or suggestions gratefully received. Benny Chain Benjamin Chain Division of Infection and Immunity Windeyer Building UCL, 46 Cleveland St. London W1T 4JF Fax 00 44 20 7679 9301 [[alternative HTML version deleted]]
Cannot reproduce with a toy example:
> data <- data.frame(a=1:3, b=4:6, c=6:8)
> colnames(data) <- c("d","e","f")
> colnames(data)
[1] "d" "e" "f"
Perhaps you need to produce more detail. Surely offering the results
of dput(a) would not tax the limits of the R-mail server.
--
David
On May 31, 2009, at 11:58 AM, Benny Chain wrote:
> I am trying to rename the column names of a data frame called
> "data". It has
> 177 columns. I have used :
>
> colnames(data) <- a
>
>
>
> where a is a vector with 177 character names.
>
>
>
> I don't get any error message, but the column names don't change
> because
> when I then type :
>
> colnames(data)
>
>
>
> I get the same set of names as before, so the assignment doesnt seem
> to have
> worked.
>
>
>
> Any ideas or suggestions gratefully received.
>
>
>
> Benny Chain
>
> Benjamin Chain
>
> Division of Infection and Immunity
>
> Windeyer Building
>
> UCL, 46 Cleveland St.
>
> London W1T 4JF
>
> Fax 00 44 20 7679 9301
>
>
>
>
> [[alternative HTML version deleted]]
>
> ______________________________________________
> 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.
David Winsemius, MD
Heritage Laboratories
West Hartford, CT
First, data is an R function so it is better to avoid it as a name for
another object. For example, use dat instead.
Try this:
data(iris)
dat=iris
colnames(iris)
[1] "Sepal.Length" "Sepal.Width" "Petal.Length"
"Petal.Width" "Species"
colnames(dat)
[1] "Sepal.Length" "Sepal.Width" "Petal.Length"
"Petal.Width" "Species"
colnames(dat)=c('a','b','c','d','e')
colnames(dat)
[1] "a" "b" "c" "d" "e"
>I am trying to rename the column names of a data frame called
"data". It
>has
> 177 columns. I have used :
>
> colnames(data) <- a
>
>
>
> where a is a vector with 177 character names.
>
>
>
> I don't get any error message, but the column names don't change
because
> when I then type :
>
> colnames(data)
>
>
>
> I get the same set of names as before, so the assignment doesnt seem to
> have
> worked.
>
>
>
> Any ideas or suggestions gratefully received.
>
>
>
> Benny Chain
>
> Benjamin Chain
>
> Division of Infection and Immunity
>
> Windeyer Building
>
> UCL, 46 Cleveland St.
>
> London W1T 4JF
>
> Fax 00 44 20 7679 9301
>
>
>
>
> [[alternative HTML version deleted]]
>
> ______________________________________________
> 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.
>