Open In App

Rounding up to the Specified Number of Significant Digits in R Programming – signif() Function

Last Updated : 10 Jun, 2020
Improve
Improve
Like Article
Like
Save
Share
Report

signif() function in R Language is used to round to the specified number of significant digits.

Syntax: signif(x, digits)

Parameters:
x: specified number
digits: significant digits

Example 1:




# R program to illustrate
# signif function
  
# Generating random number
x <- rnorm(1)
x
  
# Calling the signif() function
signif(x)


Output:

[1] 1.064923
[1] 1.06492

Example 2:




# R program to illustrate
# signif function
  
# Generating random number
x <- rnorm(1)
x
  
# Calling the signif() function
# with 3 significant digits
signif(x, 3)


Output:

[1] 1.078385
[1] 1.08

Note: The rnorm() function generates different random number each time when it runs.


Like Article
Suggest improvement
Share your thoughts in the comments

Similar Reads