Skip to content
Prev 153807 / 398500 Next

Very confused with class

Hi Robin,

You haven't said where you're getting the data from. But if the answer
is that you're using read.table, read.csv or similar to read the data
into R, then I advise you to go back to that stage and get it right
from the outset. It's very, very common to see people who are
relatively new to R splattering their code with calls to as.numeric,
just because they haven't read the data in properly in the first
place. It's also common in those who aren't new to R... So e.g. if you
are using read.table, then use the colClasses argument to specify the
classes of your columns, and use str() on the result until you're
happy with the data frame produced.

It's not entirely clear why you would have ended up with factors if
your data are numeric. That often happens when people mix characters
with numbers. Perhaps you have mixed the header row up with the data?

Anyway, what you are seeing are the integer encodings of the factors. E.g.
Factor w/ 10 levels "11","12","13",..: 1 2 3 4 5 6 7 8 9 10
[1]  1  2  3  4  5  6  7  8  9 10

But don't mess with them. Just make sure that things which shouldn't
be factors never become factors.

Dan
On Thu, Aug 21, 2008 at 03:40:58PM +0100, Williams, Robin wrote: