[R] read.table with missing data and consecutive delimiters

MacQueen, Don macqueen1 at llnl.gov
Thu Feb 12 22:56:59 CET 2015


To which I will add, you could have tried

  count.fields('test.dat', sep='$' )

which I expect would have given you 3,3,2,3, and hence a pointer to where
the problem is.

count.fields is mentioned in the "See Also" section of ?read.table

-- 
Don MacQueen

Lawrence Livermore National Laboratory
7000 East Ave., L-627
Livermore, CA 94550
925-423-1062





On 2/11/15, 12:34 PM, "Rui Barradas" <ruipbarradas at sapo.pt> wrote:

>Hello,
>
>You're missing a dollar sign: 2$$$5, not 2$$5.
>
>Hope this helps,
>
>Rui Barradas
>
>Em 11-02-2015 14:53, Tim Victor escreveu:
>> All,
>>
>> Assume we have data in an ASCII file that looks like
>>
>> Var1$Var2$Var3$Var4
>> 1$2$3$4
>> 2$$5
>> $$$6
>>
>> When I execute
>>
>> read.table( 'test.dat', header=TRUE, sep='$' )
>>
>> I, of course, receive the following error:
>>
>> Error in scan(file, what, nmax, sep, dec, quote, skip, nlines,
>>na.strings,
>>   :
>>    line 2 did not have 4 elements
>>
>> When I set fill=TRUE, e.g., read.table( 'test.dat', header=TRUE,
>>sep='$',
>> fill=TRUE )
>>
>> I get:
>>
>>    Var1 Var2 Var3 Var4
>> 1    1    2    3    4
>> 2    2   NA    5   NA
>> 3   NA   NA   NA    6
>>
>>
>> What I need is
>>
>>    Var1 Var2 Var3 Var4
>> 1    1    2    3    4
>> 2    2   NA   NA    5
>> 3   NA   NA   NA    6
>>
>> What am I missing?
>>
>> Thanks,
>>
>> Tim
>>
>> 	[[alternative HTML version deleted]]
>>
>> ______________________________________________
>> R-help at r-project.org mailing list -- To UNSUBSCRIBE and more, see
>> 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.
>>
>
>______________________________________________
>R-help at r-project.org mailing list -- To UNSUBSCRIBE and more, see
>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.



More information about the R-help mailing list