We provide effective and economically affordable online training courses for R and Python, click here for more details and course registration !

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.

For getting more knowledge of R and a preview of our training course, you can watch R tutorial videos on our YouTube channel !


0 Comments

Leave a Reply

Avatar placeholder