[R] changing colnames

arun smartpink111 at yahoo.com
Wed Aug 14 20:56:28 CEST 2013


Hi,
You could try:
dat1<- read.table(text="
X1,X2,X3
age,race,stat
12,2,35
17,6,55
",sep=",",header=TRUE,stringsAsFactors=FALSE)
colnames(dat1)<- dat1[1,]
 dat1<- dat1[-1,]
dat1[]<-lapply(dat1,as.numeric)
row.names(dat1)<- 1:nrow(dat1)
 dat1
#  age race stat
#1  12    2   35
#2  17    6   55
A.K.






________________________________
From: farnoosh sheikhi <farnoosh_81 at yahoo.com>
To: "smartpink111 at yahoo.com" <smartpink111 at yahoo.com> 
Sent: Wednesday, August 14, 2013 2:45 PM
Subject: changing colnames



Hi Arun,

I have a data set as follow:

X1 X2 X3
age race stat
12235
17655

The column names are currently  X1 X2 X3, but I want to drop them and have age, race and stat as column names, like below:

age race stat
12235
17655

Do you know how to do that?
Thanks a lot. 



More information about the R-help mailing list