[R] help regarding levels

Steven McKinney smckinney at bccrc.ca
Sat Oct 4 04:09:20 CEST 2008


Your column of data has some
character data in it, perhaps
an Excel #VALUE! or a blank or
some such entry not strictly numeric.

When R reads in such a column, it
makes that column variable into
a 'factor' variable instead of a
numeric variable, because the values
are not all numeric.

You can specify 
stringsAsFactors = FALSE
to force R to leave character
data as is if you do not want
conversion to factors.

If there is Excel cruft in a variable column,
it will end up as a factor or character variable.
You can try to make it numeric with

 df$x <- as.numeric(as.character(df$x))

(assuming you read the data into a dataframe called df)
and R will replace the Excel cruft with
NA values.

Alternatively you can clean up the Excel data
before importing it.

HTH

Steve McKinney



-----Original Message-----
From: r-help-bounces at r-project.org on behalf of K3
Sent: Fri 10/3/2008 4:09 PM
To: r-help at r-project.org
Subject: [R] help regarding levels
 
When i try to extract a column of data from an excel file and assign
it to a variable , say x, it does assign the column of data as well as
different levels.
it looks something like this when i print.

[1] 6.91 5.89 7.44 8.82
80 Levels: 1.43 102.07 103.65 106.21 106.24 107.15 108.58 11.19 ...

so how does this levels come into picture and what do they do. I
couldnot run linear regression with x as a predictor just because of
this levels. please explain.

______________________________________________
R-help at r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.



More information about the R-help mailing list