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:
- Addition: +
- Subtraction: -
- Multiplication: *
- Division: /
- Exponentiation: ^ or **
- 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:
- Sine: sin(x)
- Cosine: cos(x)
- Tangent: tan(x)
- Inverse Sine: asin(x)
- Inverse Cosine: acos(x)
- 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:
- Rounding: round(x) (rounds to the nearest integer)
- Absolute value: abs(x)
- Logarithm: log(x) (natural logarithm), log10(x) (base 10 logarithm)
- Exponential: exp(x)
- 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.
Comentarios