In this post, we list some of the most common mathematical functions in R.
abs() – compute absolute value of a numerical input.
sqrt() – compute square root of numerical input.
ceiling() – return the lowest integer no less than the input number.
floor() – return the largest integer no larger than the input number.
trunc() – trancate and return the integer part of the input number.
round() – rounding a number in terms of specified digits.
log() – calculate the natural log (base e=2.718) of a positive number.
exp() – calculate the exponential (base e=2.718) of a number.
#Absolute value
abs(-50.0)
#result
[1] 50
#Square root
sqrt(c(125, 160))
#result
[1] 11.18034 12.64911
#Ceiling
ceiling(15.5)
#result
[1] 16
#floor
floor(-12.3)
#result
[1] -13
#truncate
trunc(-23.6)
#result
[1] -23
#round
round(32.1234, digits=2)
#result
[1] 32.12
#natural logarithm
log(1000)
#result
[1] 6.907755
#Exponential function
exp(1.328)
#result
[1] 3.773489
Just note all the functions listed here can be used to apply to a vector or matrix, and the result will have the same dimension as the input object.
Click here to download Python Course Source Files !
For online Python training registration, click here ! Pandas provides flexible ways of generating data…
For online Python training registration, click here ! Data frame is the tabular data object…
Click her for course registration ! When a data frame in Python is created via…
We provide affordable online training course(via ZOOM meeting) for Python and R programming at fundamental…