[R] Error: not 'a real'?
Brian
zenlines at gmail.com
Sat Oct 20 14:43:55 CEST 2012
Hi Milan,
that's right, forgot about that one!
Sorry to bother.
Brian
On 10/20/12 14:37, Milan Bouchet-Valat wrote:
> Le samedi 20 octobre 2012 à 14:25 +0200, Brian a écrit :
>> Hi Jim,
>>
>> On 10/20/12 13:36, Jim Holtman wrote:
>>> how about supplying the context of the error. Show the lines in the file where the error occurred.
>> >
>> > Sent from my iPad
>> >
>> > On Oct 20, 2012, at 7:21, Brian <zenlines at gmail.com> wrote:
>> >
>> >> Hi List,
>> >>
>> >> when supplying a vector of atomic vector classes to read.table, I get:
>> >> # column classes
>> >> colClasses=c("character", "character","numeric", "numeric",
>> "numeric", "numeric", "numeric", "numeric",
>> >> "numeric", "numeric", "numeric", "numeric")
>> >> # Error:
>> >> Error in scan(file, what, nmax, sep, dec, quote, skip, nlines,
>> na.strings, (from #2) :
>>
>> Line #2: (with 'skip=4', so really line 4, but the first line after the
>> 'header', as indicated above)
>>
>> LAE;201001010000;2;894.6;3.9;93.8;5.3;3.1;204
>>
>>
>>>> scan() expected 'a real', got '894.6'
>> >>
>> >> How is '894.6' not 'a real [number]'?
>> >>
>> >> Thanks for the ensuing enlightenment or punishment...
>> >>
>> >> Best,
>> >> Brian
>> >>
>> >> ______________________________________________
>> >> 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.
>>
>> my full command:
>>
>> read.csv2(file=file, skip=2, na.strings = "-",
>> colClasses=c("character", "character","numeric", "numeric",
>> "numeric", "numeric", "numeric", "numeric"))
> Why didn't you tell us that you were using read.csv2() and not
> read.table() directly? read.csv() passes dec="," to read.table(), which
> explains why numbers with a dot are not detected as reals. Just pass
> dec="." to fix the problem
>
>
> Regards
>
>> Also, sorry I forgot this:
>>
>> R version 2.15.1 (2012-06-22)
>> Platform: x86_64-unknown-linux-gnu (64-bit)
>>
>> locale:
>> [1] C
>>
>> attached base packages:
>> [1] stats graphics grDevices utils datasets base
>>
>> other attached packages:
>> [1] MASS_7.3-18
>>
>> Thanks again.
>> Brian
>>
>> ______________________________________________
>> 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.
More information about the R-help
mailing list