[R] / Operator not meaningful for factors

John Kane jrkrideau at yahoo.ca
Tue May 4 18:05:48 CEST 2010



--- On Tue, 5/4/10, Petr PIKAL <petr.pikal at precheza.cz> wrote:

> From: Petr PIKAL <petr.pikal at precheza.cz>
> Subject: Re: [R] / Operator not meaningful for factors
> To: "John Kane" <jrkrideau at yahoo.ca>
> Cc: r-help at r-project.org, "vincent.deluard" <vincent.deluard at trimtabs.com>
> Received: Tuesday, May 4, 2010, 3:38 AM
> 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.

I'm not denying that it can be useful but IIRC from a discussion a couple of years ago, it was a fairly arbitary decision.

On the other hand it can be very annoying when one has some kinds of data.


> 
> 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