Tutorial Gateway

  • C
  • C#
  • Java
  • Python
  • SQL
  • MySQL
  • Js
  • BI Tools
    • Informatica
    • Talend
    • Tableau
    • Power BI
    • SSIS
    • SSRS
    • SSAS
    • MDX
    • R Tutorial
    • QlikView
  • More
    • C Programs
    • C++ Programs
    • Python Programs
    • Java Programs
    • SQL FAQ’s

R Arithmetic Operators

by suresh

The R Arithmetic operators include operators like Arithmetic Addition, Subtraction, Division, Multiplication, Exponent, Integer Division, and Modulus. All these R arithmetic operators are binary operators, which means they operate on two operands. The table below shows all the Arithmetic Operators in R Programming language with examples.

R Arithmetic Operators OperationExample
+Addition15 + 5 = 20
–Subtraction15 – 5 = 10
*Multiplication15 * 5 = 75
/Division15 / 5 = 3
%/%Integer Division – Same as Division. but it returns the integer value by flooring the extra decimals16 %/% 3 = 5. If you divide 16 with 3 you get 5.333, but the Integer division operator trims the decimal values and outputs the integer
^Exponent – It returns the Power of One variable against the other15 ^ 3 = 3375 (It means 15 Power 3 or 103).
%%Modulus – It returns the remainder after the division15 %% 5 = 0 (Here remainder is zero). If it is 17 %% 4, then result = 1.

R Arithmetic Operators Example

In this R Programming example, we are using two variables a and b, and their values are 16 and 3. Here, we are going to use these two variables to perform various arithmetic operations present in the R programming language

# Example for R Arithmetic Operators
a <- 16
b <- 3
add <- a + b
sub = a - b
multi = a * b
division = a / b
Integer_Division = a %/% b
exponent = a ^ b
modulus = a %% b

print(paste("Addition of two numbers 16 and 3 is : ", add))
print(paste("Subtracting Number 3 from 16 is : ", sub))
print(paste("Multiplication of two numbers 16 and 3 is : ", multi))
print(paste("Division of two numbers 16 and 3 is : ", division))
print(paste("Integer Division of two numbers 16 and 3 is : ", Integer_Division))
print(paste("Exponent of two numbers 16 and 3 is : ", exponent))
print(paste("Modulus of two numbers 16 and 3 is : ", modulus))

OUTPUT

R Arithmetic Operators 1

The following R Programming statement finds the exponent. It means 16 power 3 = 16 * 16 * 16 = 4096.

exponent = a ^ b

NOTE: When we are using division ( / ) operator, the result is float or decimal value. If you want to display the output as an integer value by rounding the value, then use R Integer Division ( %/% ) operator.

Placed Under: R Programming

  • R Software Download
  • Install R Packages
  • Install R Software
  • Download & Install R Studio
  • R Arithmetic Operators
  • R Comparison Operators
  • R Logical Operators
  • R If Statement
  • R If Else Statement
  • R Else If Statement
  • R Nested If Else
  • R Switch Statement
  • R Break Statement
  • R Next Statement
  • R For Loop
  • R While Loop
  • R Repeat
  • R Vector
  • R Data Frame
  • R List
  • R Arrays
  • R Matrix
  • SQL Server R Services
  • R Read CSV Function
  • R Read table Function
  • R Barplot
  • R Boxplot
  • R Histogram
  • R Pie Chart
  • R Stacked Barplot
  • R Stem and Leaf Plot
  • R Mosaic Plot
  • R ggplot2 Boxplot
  • R ggplot2 Density Plot
  • R ggplot2 Dot Plot
  • R ggplot2 Histogram
  • R ggplot2 Jitter
  • R ggplot2 Line Plot
  • R ggplot2 Scatter Plot
  • R ggplot2 Violin Plot
  • Save R ggplot using ggsave
  • R Lattice Bar chart
  • R Lattice Scatter Plot
  • R Lattice Histogram
  • R Functions
  • R Recursive Functions
  • R abs Function
  • R sqrt Function
  • R ceiling Function
  • R floor Function
  • R round Function
  • C Tutorial
  • C# Tutorial
  • Java Tutorial
  • JavaScript Tutorial
  • Python Tutorial
  • MySQL Tutorial
  • SQL Server Tutorial
  • R Tutorial
  • Power BI Tutorial
  • Tableau Tutorial
  • SSIS Tutorial
  • SSRS Tutorial
  • Informatica Tutorial
  • Talend Tutorial
  • C Programs
  • C++ Programs
  • Java Programs
  • Python Programs
  • MDX Tutorial
  • SSAS Tutorial
  • QlikView Tutorial

Copyright © 2021 | Tutorial Gateway· All Rights Reserved by Suresh

Home | About Us | Contact Us | Privacy Policy