[R] Modulus operator??

Peter Dalgaard BSA p.dalgaard at biostat.ku.dk
Sat Apr 28 21:36:26 CEST 2001


"M. Edward Borasky" <znmeb at aracnet.com> writes:

> "R contains a number of operators. They are listed in the table below.
> 
> [snip]
> 
> %  Modulus, binary"
> 
> Here's what happens on the R console:
> 
> > records <- 100000
> > modulus <- 1000
> > records % modulus
> Error: syntax error
> > records / modulus
> [1] 100
> >
> 
> I haven't tried this on Linux yet, so I don't know if it's Windows-specific.
> I did try coercing the values to integer with "as.integer" and it didn't
> help. Am I leaving something out??

Yes, another % symbol:

> records <- 100000
> modulus <- 1000
> records %% modulus
[1] 0

...which you'd obviously be excused for not knowing about. Looks like
we have a typo in the R-language manual. (We also have a curious
anomaly:

> quote("%"(records, modulus))
records % modulus

which indicates that the deparser does think % is a binary operator.
However, the tokenizer is not going to let you enter an unmatched %
because of the special operators %*%, %o%, %/%, etc. The "%" function
does not exist either. Perhaps this is a relic and R in its infancy
actually allowed x % y ?)

-- 
   O__  ---- Peter Dalgaard             Blegdamsvej 3  
  c/ /'_ --- Dept. of Biostatistics     2200 Cph. N   
 (*) \(*) -- University of Copenhagen   Denmark      Ph: (+45) 35327918
~~~~~~~~~~ - (p.dalgaard at biostat.ku.dk)             FAX: (+45) 35327907
-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html
Send "info", "help", or "[un]subscribe"
(in the "body", not the subject !)  To: r-help-request at stat.math.ethz.ch
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._



More information about the R-help mailing list