R Basic

Pi in R: Built-in Constants

Pi is a built-in R constant with a value of approximately 3.141593. It is the ratio of the circumference of a circle to its diameter.

Syntax

pi

Basic usage

print(pi)

# [1] 3.141593

Exponential value of pi

To calculate the exponential value of pi, use the exp() function.

exp(pi)

# [1] 23.14069

Cos

To calculate the cosine value of pi, use the cos() function.

cos(pi)

# [1] -1 

Sine

To find the sine value of pi, use the sin() function.

sin(pi)

# [1] 1.224647e-16

Tangent

To calculate the tangent of pi, use the tan() function and pass pi.

tan(pi)

# [1] -1.224647e-16

Arccos

To calculate the arccos value of pi, use the acos() and pass the pi.

acos(pi)

Output

[1] NaN
Warning message:
In acos(pi) : NaNs produced

It returns the NaN value.

Arcsin

To calculate the arccos value, use the asin() function.

asin(pi)

Output

[1] NaN
Warning message:
In asin(pi) : NaNs produced

It returns NaN, too.

Arctan

To calculate the arccos value, use the atan() function.

atan(pi)

# [1] 1.262627

That’s it!

Recent Posts

cbind() Function: Binding R Objects by Columns

R cbind (column bind) is a function that combines specified vectors, matrices, or data frames…

2 weeks ago

rbind() Function: Binding Rows in R

The rbind() function combines R objects, such as vectors, matrices, or data frames, by rows.…

2 weeks ago

as.numeric(): Converting to Numeric Values in R

The as.numeric() function in R converts valid non-numeric data into numeric data. What do I…

3 weeks ago

Calculating Natural Log using log() Function in R

The log() function calculates the natural logarithm (base e) of a numeric vector. By default,…

4 weeks ago

Dollar Sign ($ Operator) in R

In R, you can use the dollar sign ($ operator)  to access elements (columns) of…

1 month ago

Calculating Absolute Value using abs() Function in R

The abs() function calculates the absolute value of a numeric input, returning a non-negative (only…

2 months ago