R TUTORIAL, Part I: Calculations

R is a statistical analyzation language, and that means it is very good at data manipulation and data analyzation. One key way to analyze data is through plotting, and R excels in this field.

\[ y' = f(x,y), \qquad y(x_0 ) = y_0 . \]

Calculations

Assigning numerical values to variables can be done as follows

From within a function, access the value of variable y in the base environment (i.e., the command prompt environment)

From within a function, assign a value to variable a in the base environment (i.e., the command prompt environment)
From within a function, access the value of variable a in the base environment (i.e., the command prompt environment)
Short list of defined variables can be obtained with the linux command:
 ls()
Long list of defined variables
 ls.str()
See detailed info about the variable ab
 str(ab)
See detailed info about all variables with “ab” in their name
 ls.str(pattern=’ab’)
Open graphical data editor, to edit the value of variable A (useful for editing values in a matrix, though it works for non-matrix variables as well)
 fix(A) 

 

Controlling formating of output is accomplished with
 options(digits=6)
tells R you’d like to use 6 digits of precision in values it displays (it is only a suggestion, not strictly followed).

Machine epsilon, i.e. difference between 1 and the next largest double-precision floating-point number

 .Machine$double.eps

Define function f(x), then do uniroot(f, c(a,b)) to find a root between a and b, assuming the sign of f(x) differs at x = a and x = b. Default forward error tolerance (i.e. error in x) is fourth root of machine epsilon, (ǫ mach ) 0.25 . To specify e.g. a tolerance of 2 −52 , do uniroot(f, c(a,b), tol=2^-52).

     [,1] [,2] [,3]
[1,]    1    2    3
[2,]    4    5    6
[3,]    7    8    9

 

  1. Schiesser, W.E., An Introductory Comparison of Matlab and R, Lehigh University, Bethlehem, USA.
  2. Soetaert, K, Cash, J., Mazzia, F., Solving Differential Equations in R, 2012, Springer, Heidelberg New York Dordrecht London