I imported a csv into R and it considers my variable FERNH a factor; it isn\'t. I can\'t figure out why or how to fix it. I have reviewed the values in FERNH and they appear t
There is a character
value in there somewhere so R is acting as expected. Look at levels(height$FERNH)
to see the offending value. You can set stringsAsFactors=FALSE
on your read step or via options
, but then the column will be a character
rather than integer
.
While that may seem annoying at first, it is an excellent data quality check as well as significant memory savings if the character column contains long strings.
@Justin's pinpointed the problem. Rather than trying to find your offending value with levels
, though, you could supply colClasses='integer'
to read.csv
. Then R will raise an error when it encounters the value during reading and report what it is.