![]() |
R Programming Language is widely used for statistical computing and data analysis. One of its core strengths lies in its ability to perform various mathematical computations efficiently. Here, we’ll explore different methods and functions available in R for mathematical operations. 1. Basic Arithmetic OperationsR can handle basic arithmetic operations like addition, subtraction, multiplication, and division just like a calculator.
Output: [1] "The sum is:"
[1] 8
[1] "The difference is:"
[1] 2
[1] "The product is:"
[1] 15
[1] "The quotient is:"
[1] 1.666667 2. Mathematical Computations Using Base R FunctionsThe base R package provides numerous functions for mathematical computations. Now calculate the mean and standard deviation of a numeric vector.
Output: [1] "The mean is:" 3. Mathematical Computations Using apply() FunctionsThe apply() family of functions applies a function across the rows or columns of a matrix or data frame. So we calculate the sum of each row in a matrix.
Output: [1] 12 15 18 4. Mathematical Computations Using Custom FunctionsWe can also create custom apply functions using lapply(), sapply(), mapply(), and tapply(). Here’s an example of applying a custom function to a list.
Output: [[1]]
[1] 2
[[2]]
[1] 5
[[3]]
[1] 8 5. Mathematical Computations Using fundamental functions
Output: [1] 4 ConclusionIn R, handling everything from basic arithmetic to complex statistical analyses with ease. Through its built-in functions and powerful tools like apply(), R simplifies mathematical computations, making data analysis accessible to all. |
Reffered: https://www.geeksforgeeks.org
R Language |
Related |
---|
![]() |
![]() |
![]() |
![]() |
![]() |
Type: | Geek |
Category: | Coding |
Sub Category: | Tutorial |
Uploaded by: | Admin |
Views: | 18 |