[R] about colnames

michael watson (IAH-C) michael.watson at bbsrc.ac.uk
Tue Dec 21 10:23:33 CET 2004


Try

colnames(df)[4:6] <- c("x","y","z")

-----Original Message-----
From: r-help-bounces at stat.math.ethz.ch
[mailto:r-help-bounces at stat.math.ethz.ch] On Behalf Of
xmeng at capitalbio.com
Sent: 21 December 2004 09:45
To: r-help at stat.math.ethz.ch
Subject: [R] about colnames


Hello sir:
If there's a data frame(with name "df"):
a  b  c d  e   f 
1 10 12 20 30  100
2 3  15 16 40  200
..

If I wanna change the last 3 colunm names"d" "e" "f" respectively into
"x" "y" "z"respectively,the following is what I do:
colnames(df[4:6])<-c("x","y","z")
But no change to the colnames of df.



And if I wanna change all the colnames: colnames(df)<-letters[1:6] All
the colnames have been changed.

So I wanna know the reason,and how to change the last 3 colnames of df.

Thanks a lot!

______________________________________________
R-help at stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide!
http://www.R-project.org/posting-guide.html




More information about the R-help mailing list