## Let's do simple calculations | Introduction to Rstats (statistical analysis/scientific calculation)

Let's do a simple calculation. Rstats can be calculated using the following operators.

### Four arithmetic operations

symbol | meaning |

+ | addition |

- - | subtraction |

* | multiplication |

/ |
division |

The symbols for addition, subtraction, multiplication, and division are the same as in R language.

### Exponentiation

Exponentiation is done using "**" according to Perl's arithmetic rules. Please note that it is different from "^" in R language.

symbol | meaning |

** ** | Exponentiation |

### Remaining

The remainder is done using "%" according to Perl's arithmetic rules. Please note that it is different from "%%" in R language.

symbol | meaning |

%% | Surplus |

### Integer quotient

Rstats does not provide operators for calculating integer quotients. Please note that the R language "% /%" is not available. To find the integer quotient, use the trunc function. After performing the division, the integer part is taken out.

r->trunc($x1/$x2)

Here is an example of the calculation. In Rstats, the calculation using vectors is the basis, so we will create it using the c_ function. The c_ function is a function for creating a vector. Even if it is one numerical value, it is calculated as a vector with one element.

use strict; use warnings; use Rstats; my $x = (c_ (1) + c_ (2) - c_ (3) * c_ (4))/c_ (5) ** c_ (6); print $x;

This is the output result. The calculation result is output.

[1] -0.000576

Using c_ () at any time can be a bit annoying, but it's necessary because you're implementing the R language on top of Perl. Remember that when you do calculations in Rstats, you always use vectors to do the calculations.

For future examples, I will write from the line under "use Rstats " above for convenience, so please supplement if necessary.

Rstats provides many functions for route calculation and logarithmic calculation. For example, to calculate the route, use the "sqrt function".

my $x = r->sqrt(c_ (2)); print $x;

Output result.

[1] 1.4142135623731

The mathematical functions provided by Rstats are introduced below.

symbol | meaning |

sqrt | Calculation of √ |

abs | Absolute value |

exp exp | The bottom of the natural logarithm |

expm1 | Calculate exp(x) -1 more accurately when the absolute value of x is much less than 1 |

log | Natural logarithm |

log10 | Common logarithm (base 10 logarithm) |

log2 | Logarithm with base 2 |

sin | Sine/sine function |

cos | Cosine/cosine function |

tan | Tangent tangent function |

asin | Inverse function of sin |

acos | Inverse function of cos |

atan | Inverse function of tan |

sinh | Hyperbolic sign |

cosh | Hyperbolic cosine |

tanh | Hyperbolic tangent |

asinh | Inverse function of sinh |

acosh | Inverse function of cosh |

atanh | Inverse function of tanh |

logb | Same as log |

log1px (not implemented) | Calculate log(1 + x) more accurately when the absolute value of x is (much) less than 1 |

gamma (not implemented) | Gamma function |

lgamma (not implemented) | Same as log(gamma (x)) |

ceiling | Minimum integer greater than or equal to the argument |

floor | Maximum integer less than or equal to the argument: the so-called Gaussian symbol |

trunc | Find the integer part |

round | Rounding |

signif (x, a) not implemented yet | Round x to a digit with a valid digit (unlike sign that determines positive/0/negative) |

Introduction to Rstats (statistical analysis/scientific calculation)