[R] Help on read in a txt file

jim holtman jholtman at gmail.com
Fri Apr 25 03:27:09 CEST 2008


It seems to indicate that you don't have 592 columns on all lines.
Try the following to see how many columns are in each line:

x <- count.fields("A.txt", sep="\t")
which(x != 592)  # print out the lines that are not correct

You might also try:

read.table("a.txt", sep="\t", fill=TRUE)

On Thu, Apr 24, 2008 at 8:32 PM, ss <affysnp at gmail.com> wrote:
> Dear list,
>
> Hello! I had a problem of reading in a txt file and need your help.
> The txt file, called A, comprises of 592 columns and 34179 rows.
> I need to note that for some cells of A , A[i,j], are blank.
>
> I used read.table() and got the warning message:
>
> > A<-read.table(file="A.txt",sep="\t")
> Warning message:
> In scan(file, what, nmax, sep, dec, quote, skip, nlines, na.strings,  :
>  number of items read is not a multiple of the number of columns
> > dim(A)
> [1] 33623   592
>
> However, as some rows were missed because the original number
> of rows is 34179, after read.table(), it was decreased to 33623.
> I have no idea whether it has anything to do with the warning message.
>
> Do you have any suggestions for this problem?
>
> Thanks much,
>        Alex
>
>        [[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.
>



-- 
Jim Holtman
Cincinnati, OH
+1 513 646 9390

What is the problem you are trying to solve?



More information about the R-help mailing list