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

Rui Barradas ruipbarradas at sapo.pt
Wed Feb 11 21:34:22 CET 2015


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.
>



More information about the R-help mailing list