iconEuler Examples

R Commands in Euler

R Commands in Euler.

This is not meant to be an R environment. It just steals some functions from R, which I consider useful for Euler for users coming from R.

Some elements contradict the Euler philosphy. E.g., the function c() might easily confuse with variables c, or T,F for true and false might be better used for other variables. Other functions would overwrite Euler functions and destroy the functionality of Euler. These functions have been renamed. E.g., plot is called rplot.

You need to load this with "load r".

T:=1;
F:=0;
function c ()

  Make a vector from the elements of the arguments.
 
  The arguments can be scalars, vectors or matrices. Matrices are
  reformed to a vector. So just all elements of the matrices are
  added.
function rep (v,n)

  Repeat the vector v n times
 
  n : If it is a number the vector n is repeated n times. If it is a
  vector it must match the size of v, and the elements of v are
  repeated as often as the correspoding element of n says.
function seq (a, b, by=1, length:positive integer=none)

  Make a sequence with step size by or total length.
 
  by : an optional step size
  length : if this is specified the vector will contain n=length
  equispaced points between a and b.
function matr (A, ncol=none, nrow=none, byrow=F)

  Make a matrix from the elements of A
 
  The matrix A is reformed to a matrix with ncol columns or nrow
  rows.
 
  byrow : If true, the elements are inserted row by row, else column
  by column
function cbind ()

  Add matrices horicontally (binding columns)
function rbind ()

  Add matrices vertically (binding rows)
function summary (A)

  Summary of quantiles and mean of A.
 
  The minimal and maximal value, the 0.25,0.5,0.75 quantiles and the
  mean are printed.
function t (A)

  Tranpose of A.
function apply (A:real, where:integer, what:string)

  Apply function "what" to where=1,2 (col or row)

Distributions

function dnorm (x, m=0, sigma=1)

  Gauß density with mean m and deviation sigma
function pnorm (x, m=0, sigma=1)

  Gauß distribution with mean m and deviation sigma
function qnorm (x, m=0, sigma=1)

  Gauß distribution with mean m and deviation sigma
function rnorm (n:integer, m=0, sigma=1)

  Simulate the Gauß normal distribution n times.
function rplot (x,y=none,rtype="p")

  Plots x and y.
 
  'p' : point plot
  'l' : line plot
  'b' : both
  'h' : histgram plot
  's' : surface plot
mf:=[1,1,1,1];
function par (mfrow=none, mfcol=none)

  Sets plot parameters.
 
  The following splits the screen to plot fields. The plot functions
  will automatically advance to the next field. If write an own plot
  routine, use mfadvance() to advance to the next field. Use
  h=holding(1) to stop the plots from beeing deleted, and holding(h)
  to restore the hold state.
 
  mfrow : multi frames with [n,m] fields filled by rows
  mfcol : multi frames with [n,m] fields filled bycols
function mfadvance ()

  Advance to the next plot field.
function rhist (x,style="O")

  Histogram of the data in x.
function rboxplot ()

  Summary of the data in graphical form.
 
  Shows the 0.25,0.5,0.75 quantiles.
 
  style : If present, it is used as fill style, the default is "O",
  an unfilled style. Try "0#", "/", "\", "\/", "|".
function abline (a,b=none,color=1)

  Add a regression line to the plot

Examples