[R] How to convert a character string to a number

From: Kraft, Andreas <kran_at_ict.fraunhofer.de>
Date: Mon 23 May 2005 - 19:56:42 EST


Hi everyone,  

I have a simple problem but donīt know how to solve it.  

I read in a table from a text file that looks like that:  

-3,932200E-01 -2,000000E-01 4,999995E-02

-3,932099E-01 -1,000000E-01 3,999996E-02

-3,932000E-01 0,000000E+00 3,999996E-02

-3,931899E-01 -1,000000E-01 4,499996E-02

-3,931800E-01 -1,000000E-01 4,499996E-02

-3,931699E-01 3,000000E-01 3,499996E-02

-3,931599E-01 -3,000000E-01 3,999996E-02

-3,931500E-01 0,000000E+00 2,499996E-02

-3,931399E-01 0,000000E+00 2,499996E-02

-3,931300E-01 0,000000E+00 3,499996E-02  

but when I try to to plot the values from the second column, the plot shows the wrong values.  

That's what I do in R:  

read.table("C:\\Messdaten\\epp1_1_ver.txt")->sh1

> sh1[1:10,2]

[1] -2.000000E-01 -1.000000E-01 0.000000E+00 -1.000000E-01 -1.000000E-01 3.000000E-01 -3.000000E-01 0.000000E+00

[9] 0.000000E+00 0.000000E+00

1707 Levels: -1,000000E-01 -1,000000E+00 -1,000000E+01 -1,002000E+02 -1,003000E+02 -1,004000E+02 ... 9,980000E+01

> sh1[1:10,2]->a

> cbind(x=seq(1,10,by=1),y=a)

       x y

[1,] 1 436

[2,] 2 321

[3,] 3 1007

[4,] 4 321

[5,] 5 321

[6,] 6 1353

[7,] 7 548

[8,] 8 1007

[9,] 9 1007

[10,] 10 1007  

Why do I get those values? Why is for example -2,000000E-01 equal to 436?

I need to convert the values from -2,000000E-01 to -0.2 - how can I do this?  

Thank you for your suggestions,  

Andreas Kraft  

        [[alternative HTML version deleted]]



R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html Received on Mon May 23 20:29:17 2005

This archive was generated by hypermail 2.1.8 : Fri 03 Mar 2006 - 03:32:00 EST