Skip to content
Prev 300066 / 398502 Next

read.table with numeric row names

Hi Peter,

I copied the data from your email and run it again.

dat1<-read.table(text="
? 2.5? 3.6? 7.1? 7.9
? 100? 3????? 4????? 2??? 3
? 200? 3.1? 4????? 3????? 3
? 300? 2.2? 3.3? 2??? 4
? ",sep="",header=TRUE) 

dat1
??? X2.5 X3.6 X7.1 X7.9
100? 3.0? 4.0??? 2??? 3
200? 3.1? 4.0??? 3??? 3
300? 2.2? 3.3??? 2??? 4


colnames(dat1)<-gsub("^[X](.*)","\\1",colnames(dat1))


I am? not sure what happened with your end.? May be you could try
readtable(...., fill=TRUE)

I guess Chi was able to read it as I understood from his email: 
("Thanks. It works very good.Chi"

A.K.




----- Original Message -----
From: peter dalgaard <pdalgd at gmail.com>
To: arun <smartpink111 at yahoo.com>
Cc: kexinz <zhangchicool at gmail.com>; R help <r-help at r-project.org>
Sent: Friday, July 13, 2012 10:27 AM
Subject: Re: [R] read.table with numeric row names
On Jul 13, 2012, at 04:27 , arun wrote:

            
(This didn't survive too well in mail:
+? 2.5? 3.6? 7.1? 7.9 
+? 100? 3? ? ? 4? ? ? 2? ? 3 
+? 200? 3.1? 4? ? ? 3? ? ? 3 
+? 300? 2.2? 3.3? 2? ? 4 
+? ",sep="",header=TRUE)? 
Error in read.table(text = " \n 2.5? 3.6? 7.1? 7.9 \n 100? 3? ? ? 4? ? ? 2? ? 3 \n 200? 3.1? 4? ? ? 3? ? ? 3 \n 300? 2.2? 3.3? 2? ? 4 \n ",? : 
? more columns than column names

Not sure exactly what happened there...)
However, adding check.names=FALSE should be more expedient.