top of page

R Math

R is a programming language and environment specifically designed for statistical computing and data analysis. It provides extensive functionality for mathematical operations and statistical computations. Here are some common mathematical operations and functions in R:


Basic Arithmetic Operations:

R supports the standard arithmetic operations:


  1. - Addition: +

  2. - Subtraction: -

  3. - Multiplication: *

  4. - Division: /

  5. - Exponentiation: ^ or **

  6. - Modulo: %% (returns the remainder of division)



a <- 5
b <- 2

add_result <- a + b    # 7
sub_result <- a - b    # 3
mul_result <- a * b    # 10
div_result <- a / b    # 2.5
exp_result <- a^b      # 25
mod_result <- a %% b   # 1


Trigonometric Functions:

R provides built-in functions for various trigonometric operations:


  1. - Sine: sin(x)

  2. - Cosine: cos(x)

  3. - Tangent: tan(x)

  4. - Inverse Sine: asin(x)

  5. - Inverse Cosine: acos(x)

  6. - Inverse Tangent: atan(x)



x <- 0.5

sin_result <- sin(x)        # 0.4794255
cos_result <- cos(x)        # 0.8775826
tan_result <- tan(x)        # 0.5463025
asin_result <- asin(x)      # 0.5235988
acos_result <- acos(x)      # 1.047198
atan_result <- atan(x)      # 0.4636476

Other Mathematical Functions:


R offers various mathematical functions to perform operations like rounding, absolute value, logarithm, square root, and more:

  1. - Rounding: round(x) (rounds to the nearest integer)

  2. - Absolute value: abs(x)

  3. - Logarithm: log(x) (natural logarithm), log10(x) (base 10 logarithm)

  4. - Exponential: exp(x)

  5. - Square root: sqrt(x)


x <- 2.3

round_result <- round(x)       # 2
abs_result <- abs(x)           # 2.3
log_result <- log(x)           # 0.8329091
log10_result <- log10(x)       # 0.3617278
exp_result <- exp(x)           # 9.974182
sqrt_result <- sqrt(x)         # 1.516575

These are just a few examples of the mathematical operations and functions available in R. The language provides a comprehensive set of mathematical and statistical functions to handle a wide range of numerical computations.

Related Posts

See All

A Comprehensive Guide to R Data Types

Introduction In the realm of data analysis and statistical computing, the R programming language stands as a powerful tool. Understanding data types in R is fundamental to unleashing its full potentia

R - CSV Files

Getting and Setting the Working Directory You can check which directory the R workspace is pointing to using the getwd() function. You can also set a new working directory using setwd()function. # Get

Comments


bottom of page