Skip to content

HELP - as.numeric changing column data

1 message · William Dunlap

#
By the way, here is an example where the advice in FAQ 7.10 (change the
factor
columns to numeric) would give incorrect results.  The incorrect header
setting
in the call to read.table causes an extra row of non-numeric data to appear
at the
start of the imported data.

  > txt <- "ColA ColB\n101 102\n201 202\n"
  > str(read.table(text=txt))
'  data.frame':   3 obs. of  2 variables:
   $ V1: Factor w/ 3 levels "101","201","ColA": 3 1 2
   $ V2: Factor w/ 3 levels "102","202","ColB": 3 1 2
  > str(read.table(text=txt, header=TRUE))
  'data.frame':   2 obs. of  2 variables:
   $ ColA: int  101 201
   $ ColB: int  102 202


Bill Dunlap
TIBCO Software
wdunlap tibco.com

On Wed, Jan 6, 2016 at 1:26 PM, Andy Schneider <andyschneider85 at gmail.com>
wrote: