How to use ntile to calculate Deciles In R Language
ntile() function belongs to dplyr package. This function will automatically divide the frequencies and place them in required group
Syntax:
ntile(data, num)
Parameter:
- data in consideration
- num is the required number of groups
Example:
In this example, we calculate deciles using ntile() function in the R language.
R
# import library library (dplyr) # create dataframe df<- data.frame (x= c (2,13,5,36,12,50), y= c ( 'a' , 'b' , 'c' , 'c' , 'c' , 'b' )) # calculate deciles res<- ntile (df,10) # display res |
Output:
[1] 1 2 1 3 2 4 5 6 8 9 10 7
How to Calculate Deciles in R?
In this article, we will discuss how to calculate deciles in the R programming language.
Deciles are numbers that split a dataset into ten groups, each of equal frequency.