R Programs to Add, Sub, Mul, and Div

R Programs to Add, Sub, Mul, and Div

Basic Arithmetic Operations in R:

1. Addition: In R, addition is a basic arithmetic operation performed using the + operator. It is used to add two or more numerical values.

2. Subtraction: Subtraction is performed in R using the - operator. It subtracts the right operand from the left operand.

3. Multiplication: The * operator is used for multiplication in R. It multiplies two or more numerical values.

4. Division: Division is performed in R using the / operator. It divides the left operand by the right operand.

R Programs for Basic Arithmetic Operations:

Input:

2+3 //Add
2-3 //Sub
2*3 //Mul
2/3 //Div
2+2+3*4-4/3 // Add, Mul, Sub, Div

Output:

5
[1] -1
[1] 6
[1] 0.6666667
[1] 14.66667

(Or)

With input variable:

x=6 
y=2 
x + y
x-y
x*y
x/y

Output:

8
4
12
3 

Conclusion:

In conclusion, basic arithmetic operations (Addition, Subtraction, Multiplication, and Division) are fundamental in mathematics and programming. R programming language provides simple and intuitive syntax for performing these operations. The presented R programs demonstrate how to perform each operation with given input values. Understanding and utilizing these operations are essential for various data analysis and statistical tasks in R. These programs can be modified and extended to handle user input or perform calculations with more complex expression.

Scroll to Top