Re: [R] / Operator not meaningful for factors

From: Gabor Grothendieck <ggrothendieck_at_gmail.com>
Date: Sun 15 Jan 2006 - 22:20:33 EST

But factors are numeric:

mode(factor(1:3)) # numeric

so the numerator or denominator are likely a factor. Try using str and class rather than mode to investigate this.

On 1/15/06, Vivek Satsangi <vivek.satsangi@gmail.com> wrote:
> Folks,
> I have a very basic question. The solution eludes me perhaps because
> of my own lack of creativity. I am not attaching a fully reproducible
> session because the issue may well be becuase of the way the data file
> is, and the data file is large (and I don't know whether I can legally
> distribute it). If people can suggest things that might be wrong in my
> data or the way that I am reading it, I would be most grateful.
>
> I get the following error message in the session quoted at the end of
> this email:
> / not meaningful for factors in: Ops.factor(BookValuePS, Price)
>
> As you can see in that some session, I check that the two vectors

> being divided are numeric. I also check that the divisor is not 0 at
> any index. I also believe that this is not because of the NA's in the

> data. My question is, what are other "problems" that can cause the /
> operator to not be meaningful?
>
> I did try some simple examples to try to get the same error. However,
> I am not sure how to put the same NA's that one gets from
> read.table() into a vector:
> > a <- c(1, 2, 3, NA);
> > a
> [1] 1 2 3 NA
> > b <- c( 1, 2, 3, 4);
> > c <- b / a;
> > b
> [1] 1 2 3 4
> > a <- c(1, 2, 3, );
> > c <- b/a;
> Warning message:
> longer object length
> is not a multiple of shorter object length in: b/a
>
>
> ******** Quoted Session below ********
> > explainPriceSimplified <- read.table("combinedClean.csv",
> + sep = ",", header=TRUE);
> > attach(explainPriceSimplified);
> > summary(explainPriceSimplified);
> Symbol Date Price EPS
> BookValuePS
> XL : 98 Min. :19870630 22 : 61 Min. :-1.401e+05
> Min. :-6.901e+05
> ZION : 97 1st Qu.:19910930 26.5 : 61 1st Qu.: 4.650e-01
> 1st Qu.: 3.892e+00
> YRCW : 72 Median :19960331 27.5 : 58 Median : 1.060e+00
> Median : 7.882e+00
> AA : 71 Mean :19957688 30 : 58 Mean :-1.534e+01
> Mean : 1.515e+02
> ABS : 71 3rd Qu.:20001231 25 : 56 3rd Qu.: 1.890e+00
> 3rd Qu.: 1.444e+01
> ABT : 71 Max. :20041231 (Other):29561 Max. : 5.309e+03
> Max. : 3.366e+06
> (Other):29624 NA's : 249 NA's : 2.460e+02
> NA's : 4.760e+02
> FiscalQuarterRep F12MRet
> 2004/2F: 482 Min. :-100.00
> 2003/4F: 471 1st Qu.: -8.82
> 2004/1F: 470 Median : 10.57
> 2004/3F: 470 Mean : 13.36
> 2003/3F: 464 3rd Qu.: 31.12
> 2003/2F: 463 Max. :4700.00
> (Other):27284 NA's : 463.00
> > mode(Price)
> [1] "numeric"
> > mode(EPS)
> [1] "numeric"
> > mode(BookValuePS)
> [1] "numeric"
> > BP <- BookValuePS / Price ;
> Warning message:
> / not meaningful for factors in: Ops.factor(BookValuePS, Price)
> > which(Price==0)
> numeric(0)

> >
>
>
> --
> -- Vivek Satsangi
> Student, Rochester, NY USA
>
> ______________________________________________
> R-help@stat.math.ethz.ch mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
>



R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html Received on Sun Jan 15 22:26:55 2006

This archive was generated by hypermail 2.1.8 : Mon 16 Jan 2006 - 02:07:55 EST