# [R] Translate octave code to R

Robin Hankin r.hankin at auckland.ac.nz
Sun Mar 17 23:23:26 CET 2002

```Hello Rafael

A good place to start would be my R-and-octave.txt helpfile (in
contributed docs on CRAN), which lists octave commands and their
(near) R equivalent.

If you still have problems, I'd be very happy to help.

robin

>
> Hello,
>
> I'd like to translate de code below, write in octave, to R. I'm learning to
> operate R a few time ago, and an example of translation will be useful for
> me.
> This code is my lectures in an undergraduate course of statistical
> computing.
>
>
>
> echo off;
> k=0;
> while (k<>1)
>   n = input('a prime: ');
>   D = 2;
>   r = n - D * floor((n/D));
>   while((D <= sqrt(n) & (r <> 0)))
>     D=D+1;
>     r = n - D * floor((n/D));
>   endwhile;
>   if ((n - D * floor((n/D))) <> 0)
>     disp('É primo');
>     k=1;
>   else
>     disp('try again');
>   end;
> end;
>
>
> #start of pseudo-random numbers generation
>
> m = 2**35;
> a = (2**7)+3;
> c = a;
> x(1)=n;#seed
> u(1)=0;
> i=1;
> while (i<=500)
>
>   x(i+1)=((a*x(i)+c) - (m*floor(((a*x(i)+c)/m))));
>   u(i)=(x(i+1)/m);
>   i++;
>
> endwhile;
> hist(u);
>
>
>
> Thank you for attention,
>
> Rafael Bertola
> (UNICAMP (University of Campinas) - Brasil)
>
>
>
>
>
> -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
> 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
> _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
>

--

Robin Hankin, Lecturer,
School of Geographical and Environmental Science
Private Bag 92019 Auckland
New Zealand

r.hankin at auckland.ac.nz
tel 0064-9-373-7599 x6820; FAX 0064-9-373-7042

as of: Mon Mar 18 10:18:00 NZST 2002
This (linux) system up continuously for:  200 days, 17 hours, 13 minutes
-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
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
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._

```