[R] Reading a tab delimitted text

Douglas Bates bates at stat.wisc.edu
Tue Nov 30 23:03:05 CET 2004


Srinivas Iyyer wrote:
> Dear group,
>  I have a tab delimitted text file with 21 column and
> 1988 rows. When I read the file:
> 
> D1 <-
> read.table(file="gist_data1.txt",sep="\t",header=T)
> 
>>dim(D1)
> 
> [1] 1811   20
> 
> It reads only 1811 rows from that file.
> 
> I saved this file as CSV file and I read it again
> using:
> 
> 
>>D1 <-
> 
> read.csv(file="gist_data1.txt",sep=",",header=T)
> 
> 
> 
>>dim(D1)
> 
> [1] 1987    1
> 
> 
> 
> This timer it reaad correct number of rows and wrong
> column numbers. 
> 
> Can any one suggest how to read a tab-delimited text
> file and read in corect number of lines. 
> 
> 
> thank you.

Check for the presence of unexpected comment characters or quote 
characters in the file you are reading.  Alternatively, try setting 
quote='', comment='' in the call to read.table.




More information about the R-help mailing list