R Basic

Pi in R: Built-in Constants

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

Syntax

pi

Visual representation

Example 1: Basic usage

print(pi)

Output

[1] 3.141593

Example 2: Exponential value of pi

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

exp(pi)

Output

[1] 23.14069

Example 3: Cos value of pi

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

cos(pi)

Output

[1] -1

Example 4: Sine value of pi

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

sin(pi)

Output

[1] 1.224647e-16

Example 5: Tangent of pi

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

tan(pi)

Output

[1] -1.224647e-16

Example 6: Arccos value of pi

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.

Example 7: Arcsin value of pi

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.

Example 8: Arctan value of pi

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

atan(pi)

Output

[1] 1.262627

That’s it!

Recent Posts

dplyr group_by() Function in R

The group_by() function from the dplyr package allows us to group data frames by one…

3 hours ago

R dplyr::slice() Function

The dplyr::slice() function subsets rows by their position or index within a data frame. If…

2 days ago

How to Create an Empty Vector and Append Values in R

R vectors are atomic, which means they have homogeneous data types. They are contiguous in…

3 days ago

How to Remove Single and Multiple Columns from Data Frame in R

DataFrames are like tables that contain rows and columns. Each column can have a different…

4 days ago

How to Convert Date to Numeric in R

Dates in R are stored as the number of days since 1970-01-01, so converting a…

5 days ago

How to Create a Data Frame from Vectors in R

In R, you can think of a vector as a series of values in a…

2 weeks ago