[R] / Operator not meaningful for factors

Petr PIKAL petr.pikal at precheza.cz
Tue May 4 09:38:25 CEST 2010


Hi

r-help-bounces at r-project.org napsal dne 04.05.2010 00:50:00:

>  I think that you are correct.  R has the annoying habit of converting 
> character data to factors when you don't want it to while it is 
importing 
> data.  This is because the in the option "stringsAsFactors" is set to 
TRUE for
> some weird historical reasons.

It is a matter of opinion. I consider it quite useful feature. If I see by

str(some.data) or summary(data0 that numeric columns are factors I know 
something is wrong with input.

and when I want to use ggplot, xyplot or just plot my data with different 
colours/sizes/pchs/.... it is quite easy to use as.numeric(my.factor) to 
get numeric representation of levels.

Finally you can easily change labels, concatenate levels and so on.

Just my 2 cents.

Regards
Petr



> 
> Try the command str(insert name of data) and see what happens.  It 
should show
> you which columns of data are being treated as factors.
> 
> You can convert the back to character or to numeric.  See the FAQ Part 7 
"How 
> do I convert factors to numeric? " or you can use the String as options 
> command in the read.table to FALSE
> 
> Something like this should work, I think, but it's not tested
> read.table("C:/rdata/trees.csv", stringsAsFactors=FALSE)
> 
> 
> 
> 
> 
> --- On Mon, 5/3/10, vincent.deluard <vincent.deluard at trimtabs.com> 
wrote:
> 
> > From: vincent.deluard <vincent.deluard at trimtabs.com>
> > Subject: Re: [R] / Operator not meaningful for factors
> > To: r-help at r-project.org
> > Received: Monday, May 3, 2010, 6:22 PM
> > 
> > Hi there,
> > 
> > This will sound very stupid because I just started using R
> > but I see you had
> > similar problems.
> > 
> > I just loaded a very large dataset (2950*6602) from csv
> > into R. The format
> > is ticker=row, date=column.
> > Every time I want to compute basic operations, R returns
> > "In Ops.factor: not
> > meaningful for factors"
> > 
> > I believe it is because R does not read the data as numbers
> > but I am not
> > sure. Can anybody help?
> > 
> > Thanks! 
> > -- 
> > View this message in context: 
http://r.789695.n4.nabble.com/Operator-not-
> meaningful-for-factors-tp791563p2124697.html
> > Sent from the R help mailing list archive at Nabble.com.
> > 
> > ______________________________________________
> > 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.
> >
> 
> ______________________________________________
> 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