Leo Umesh avatar

Basic Mathematical Operations in R Programming

leoumesh

Published: 26 Sept 2023 › Updated: 26 Sept 2023Basic Mathematical Operations in R Programming

Basic Mathematical Operations in R Programming

image.png

Image Source

This post is gonna be pretty simple and deals with the basic mathematical operations in R programming before we go into other concepts. Some of the built-in functions are highly helpful as you move along. The four basic mathematical operations which are addition, subtraction, multiplication and division are pretty straightforward in R and easier to understand.

a <- 2+3
a

b <- 5-4
b

c <- 4*5
c

d <- 10/4
d



We will also get the output as expected:

image.png

Next is the exponential which can be done by using '^' symbol (for example: 2^4 which is equal to 16). Another is the modulus operator. In R double percentage sign is used to perform modulus operation (for example: 14%%5 which gives us result as 4).

Down here we will take a look at some built-in R functions used for mathematical purposes.

e <- 2^4
e

f <- 14%%5
f

sqrt(81)

abs(-21)

g <- 20/3
g
round(g, digits=2)

The sqrt() function calculates the square root of a number. The abs() function returns the absolute value of a number. The round() function returns the rounded value of a number. Parameters digits is used to specify the number of decimal points that you want your number to be rounded off.

The output is as follows:

image.png

Likewise there are many built-in math's functions like finding trigonometrical values, logarithmic values, generating and searching a pattern in number and so on in R.

Leave Basic Mathematical Operations in R Programming to:

Written by

I am just a passionate blogger.

Read more #blog posts


Best Posts From Leo Umesh

We have not curated any of leoumesh's posts yet. But you can encourage our curation team to review posts by visiting them regularly and by referring other readers. Because we give priority to frequently read content.

More Posts From Leo Umesh