[R] Simple numeric "as.is" question

Prof Brian Ripley ripley at stats.ox.ac.uk
Mon Mar 15 20:16:33 CET 2004


On Mon, 15 Mar 2004, Tom Blackwell wrote:

> Try  x2 <- as.numeric(as.character(x))
>      hist(x2)
> 
> I'm not a Windows user, so I can't test this before sending.
> It might solve the problem, might not.
> 
> (Flame !! :  This is just ONE MORE example of the difficulties
> caused by the default behavior of  read.table()  to make things
> into factors.  I sincerely wish the default were to preserve
> character data as character.)

Eh?  Misusing read.table where scan() is appropriate is hardly a cause for 
flaming read.table.  The point is that if this were numeric data, 
read.table would have read it as numeric, so it is not and that should be 
resolved first.

Be careful what you wish: *all* data on a file is character, so you 
would always get character columns -- you might as well use a character 
matrix.

> -  tom blackwell  -  u michigan medical school  -  ann arbor  -
> 
> On Mon, 15 Mar 2004, Janet Gannon wrote:
> 
> > I am reading a list of numbers from my clipboard, and have been
> > successful, except I can't make a histogram as R doesn't recognize my
> > variable as numeric.  I know I need to use "as.is", but the specifics
> > escape me.
> >
> > I have used x<-read.table("clipboard", header=F) to import from a txt
> > file.  How do make this numeric?  Thanks, J.

-- 
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