R arithmetic operations
kodingwindow@kw:~$ R
R version 4.3.3 (2024-02-29) -- "Angel Food Cake"
Copyright (C) 2024 The R Foundation for Statistical Computing
Platform: x86_64-pc-linux-gnu (64-bit)

R is free software and comes with ABSOLUTELY NO WARRANTY.
You are welcome to redistribute it under certain conditions.
Type 'license()' or 'licence()' for distribution details.

  Natural language support but running in an English locale

R is a collaborative project with many contributors.
Type 'contributors()' for more information and
'citation()' on how to cite R or R packages in publications.

Type 'demo()' for some demos, 'help()' for on-line help, or
'help.start()' for an HTML browser interface to help.
Type 'q()' to quit R.

Addition
> 1 + 1
[1] 2

Subtraction
> 1 - 1
[1] 0

Multiplication
> 10 * 10
[1] 100

Division
> 1 / 0
[1] Inf

Power or exponent
> 0 ** 0
[1] 1
> 0 ^ 0
[1] 1

Remainder
> 10 %% 3
[1] 1
R sqrt() function
Square root of a number
> sqrt(25)
[1] 5

> sqrt(2)
[1] 1.414214
R sum() function
> 1:10 + 11:20
[1] 12 14 16 18 20 22 24 26 28 30

Sum of sequence 1 to 10
> sum(1:10)
[1] 55
R mean() and median() functions
> mean(1:10)
[1] 5.5

> median(1:10)
[1] 5.5
R identical() function
> identical(1,1)
[1] TRUE

> identical(1,1.0)
[1] TRUE

> identical(0 ^ 0,0 ** 0)
[1] TRUE
R factorial() function
Factorial of a number
> factorial(0)
[1] 1

> factorial(100)
[1] 9.332622e+157
R trigonometric function
> pi
[1] 3.141593

> sin(30)
[1] -0.9880316

> tan(90)
[1] -1.9952
Advertisement