round_any() Function of plyr Package in R
In this article, we will discuss the round_any() function with its examples from plyr() package in the R programming language.
Installation
Before knowing this, we have to install and load the plyr() package.
Syntax to install and load the plyr package in the R console:
Install: install.packages("plyr") Load: library("plyr")
round_any() function in r rounds to a multiple of any number that we have to specify within the round_any() function.Its syntax is as follows:
Syntax:
round_any(input_data,rounding_value)
where, input_data may be a vector or a dataframe and value is the rounding value.
Example 1:
In this example, we are creating a vector with 5 elements from 1 to 5, and then calling the round_any() function passed with the vector and the rounding value to 1.3.
R
# load the package library ( "plyr" ) # get round round_any ( c (1,2,3,4,5), 1.3) |
Output:
1] 1.3 2.6 2.6 3.9 5.2
Example 2:
In this example, we are using the same vector used in the previous example of 5 elements and here we are changing the value to the rounding value passed in the function round_any() to 1.9 to compare the changes with the previous example in the R language,.
R
# load the package library ( "plyr" ) # get round round_any ( c (1,2,3,4,5), 1.9) |
Output:
[1] 1.9 1.9 3.8 3.8 5.7
Please Login to comment...