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

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:

filter_none

edit
close

play_arrow

link
brightness_4
code

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

chevron_right


Output:



[1] 1.064923
[1] 1.06492

Example 2:

filter_none

edit
close

play_arrow

link
brightness_4
code

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

chevron_right


Output:

[1] 1.078385
[1] 1.08

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

My Personal Notes arrow_drop_up

Recommended Posts:


Check out this Author's contributed articles.

If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.

Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.


Article Tags :

Be the First to upvote.


Please write to us at contribute@geeksforgeeks.org to report any issue with the above content.