[R] Strange problem with reading a pipe delimited file
Duncan Murdoch
murdoch.duncan at gmail.com
Sat Nov 17 22:45:10 CET 2012
On 12-11-17 4:34 PM, Brian Feeny wrote:
>
> On Nov 17, 2012, at 4:27 PM, Duncan Murdoch wrote:
>>>
>>
>> I would suggest reading the help file: read.delim only looks at the
>> first 5 lines to determine the number of columns if you don't specify
>> the colClasses.
>>
>> Duncan Murdoch
>>
>
> Duncan,
>
> I have tried to pass colClasses but R complains:
>
> test <- read.delim("mypaths4.txt", sep="|", quote=NULL, header=F,
> colClasses=c("character","character","character","character","character","character","character","character","character","character"),
> fill=TRUE)
> Warning message:
> In read.table(file = file, header = header, sep = sep, quote = quote, :
> cols = 9 != length(data) = 10
>
>
> once again this is with data:
>
> A|B|C|D
> A|B|C|D|E|F
> A|B|C|D|E
> A|B|C|D|E|F|G|H|I
> A|B|C|D
> A|B|C|D|E|F|G|H|I|J
>
> Any idea?
Sure, it's warning you that your file looks like it has 9 columns, but
you said it has 10, and it will not have generated good column names
(but it will have read the file properly).
If you give it 10 names (e.g. using col.names=LETTERS[1:10]) it will be
happy.
Duncan Murdoch
More information about the R-help
mailing list