[R] / Operator not meaningful for factors
petr.pikal at precheza.cz
Tue May 4 10:12:42 CEST 2010
"Katya Mauff" <Katya.Mauff at uct.ac.za> napsal dne 04.05.2010 09:53:49:
> another way to do it (if you are still having problems) is to use sapply
> (yourdataname,data.class) after you've read it in, which will tell you
> data class of each of your variables (factor, numeric etc). You can then
> change your factor variables to numeric by typing yourdataname
You can not!!!!! When you do it you will get numeric **representation** of
 -1.1550254 -0.4578429 -0.6089007 -1.7378599 0.1297853
 -1.15502538070463 -0.457842907389024 -0.608900689299125
5 Levels: -1.73785992416606 -1.15502538070463 ... 0.129785271221269
 2 4 3 1 5
> >>> Petr PIKAL <petr.pikal at precheza.cz> 2010/05/04 09:38 AM >>>
> 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
> > 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
> 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
> 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.
> > 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
> > do I convert factors to numeric? " or you can use the String as
> > 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>
> > > 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:
> > 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
> > > 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
> > and provide commented, minimal, self-contained, reproducible code.
> R-help at r-project.org mailing list
> PLEASE do read the posting guide
> and provide commented, minimal, self-contained, reproducible code.
> UNIVERSITY OF CAPE TOWN
> This e-mail is subject to the UCT ICT policies and e-mail disclaimer
> on our website at http://www.uct.ac.za/about/policies/emaildisclaimer/
> obtainable from +27 21 650 4500. This e-mail is intended only for the
> (s) to whom it is addressed. If the e-mail has reached you in error,
> notify the author. If you are not the intended recipient of the e-mail
> not use, disclose, copy, redirect or print the content. If this e-mail
> related to the business of UCT it is sent by the sender in the sender's
> individual capacity.
More information about the R-help