[R] read.table() and scientific notation

Prof Brian Ripley ripley at stats.ox.ac.uk
Tue Oct 10 13:03:31 CEST 2006


On FC5 Linux:

gannet% cat > foo.dat
a 1 2e-4
b 2 3e-8
gannet% R
...
> read.table("foo.dat")
   V1 V2    V3
1  a  1 2e-04
2  b  2 3e-08
> sapply(read.table("foo.dat"), class)
        V1        V2        V3
  "factor" "integer" "numeric"

so please tell us your environment and give a reproducible example.  (This 
is using the OS function strtod, so it might be a deficiency in your OS's 
implementation of ISO C.)

On Tue, 10 Oct 2006, January Weiner wrote:

> Dear all,
>
> I am having troubles importing values written as scientific notation
> using read.table(). I'm sure this is a frequent problem, as many
> people in my lab have this problem as well, so I'm sure that I just
> have troubles googling for the right solution.
>
> The problem is, that, given a file like that:
>
> a 1 2e-4
> b 2 3e-8
> ...
>
> the third column gets imported as a factor, or a string if I set the
> as.is parameter of read.table to TRUE for this column. However, I just
> want a simple numeric vector :-) I'm sure there is a simple trick for
> this. If you can point me to the right function, or manual, I think I
> should be able to find out the details myself.
>
> Thanks in advance,
> January
>
>

-- 
Brian D. Ripley,                  ripley at stats.ox.ac.uk
Professor of Applied Statistics,  http://www.stats.ox.ac.uk/~ripley/
University of Oxford,             Tel:  +44 1865 272861 (self)
1 South Parks Road,                     +44 1865 272866 (PA)
Oxford OX1 3TG, UK                Fax:  +44 1865 272595



More information about the R-help mailing list