Skip to content
Prev 169506 / 398506 Next

How to convert Charagter variables into numeric

Dear Arup,

It's very difficult to know what's going on without more information. What
is the form of the data that you're importing and how are you reading the
data? I ask because the most common way of getting data into R is probably
via read.table(), which by default converts character data to factors but
reads numbers as numeric. If a "column" of input data has one or more
non-numeric entries (other than the default missing-data indicator NA), it
will be read as a factor, even if most entries in the column are numbers.

To answer your more general question, R has a number of "coercion" functions
prefixed by "as." for changing data from one form to another: For example,
if by "numeric to categorical" you mean numeric to a factor, then
as.factor() will do the trick. There is also the more general coercion
function as() (see ?as).

I hope this helps,
 John

------------------------------
John Fox, Professor
Department of Sociology
McMaster University
Hamilton, Ontario, Canada
web: socserv.mcmaster.ca/jfox
On
into
http://www.nabble.com/How-to-convert-Charagter-
http://www.R-project.org/posting-guide.html