Skip to content

How to convert a character string to a number

2 messages · Kraft, Andreas, Stephen D. Weigand

#
Dear Andreas,
On May 23, 2005, at 4:56 AM, Kraft, Andreas wrote:

            
...
Read the help for read.table() and use dec = ",".

Also, before you correct the call to read.table, if you enter

R> str(sh1)

you'll see something like:

R> str(sh1)
`data.frame':	10 obs. of  3 variables:
  $ V1: Factor w/ 10 levels "-3,931300E-01",..: 10 9 8 7 6 5 4 3 2 1
  $ V2: Factor w/ 5 levels "-1,000000E-01",..: 2 1 4 1 1 5 3 4 4 4
  $ V3: Factor w/ 5 levels "2,499996E-02",..: 5 3 3 4 4 2 3 1 1 2

which gives you some very helpful information.  In particular, it
shows that sh1 consists of factors.

Good luck,

Stephen