Calculate percentile, quantile, N tile of dataframe in R using dplyr (create column with percentile rank)

Quantile, Decile and Percentile can be calculated using ntile() Function in R. Dplyr package is provided with mutate() function and ntile() function. The ntile() function is used to divide the data into N bins. In this example we will be creating the column with percentile, decile and quantile rank

 

Quantile rank in R:

We will be using mtcars data to depict the example of ntile() function.

library(dplyr)

mydata<-mtcars
df1 = mutate(mydata, quantile_rank = ntile(mydata$mpg,4))
df1

So in the resultant data frame quantile rank is calculated and populated across

Calculate percentile, quantile, N tile of dataframe in R using dplyr (create column with percentile rank 1

 

Decile rank in R:

library(dplyr)

mydata<-mtcars
df1 = mutate(mydata, decile_rank = ntile(mydata$mpg,10))
df1

So in the resultant data frame decile rank is calculated and populated across

Calculate percentile, quantile, N tile of dataframe in R using dplyr (create column with percentile rank 2

 

 Percentile rank in R:

library(dplyr)

mydata<-mtcars
df1 = mutate(mydata, percentile_rank = ntile(mydata$mpg,100))
df1

So in the resultant data frame percentile rank is calculated and populated across

Calculate percentile, quantile, N tile of dataframe in R using dplyr (create column with percentile rank 3

 

Calculate percentile, quantile, N tile of dataframe in R using dplyr (create column with percentile rank)                                                                                                                Calculate percentile, quantile, N tile of dataframe in R using dplyr (create column with percentile rank)