Create Quantiles of a Data Set in R Programming – quantile() Function

quantile() function in R Language is used to create sample quantiles within a data set with probability[0, 1]. Such as first quantile is at 0.25[25%], second is at 0.50[50%], and third is at 0.75[75%].

Syntax: quantile(x)

Parameters:
x: Data set

Example 1:

filter_none

edit
close

play_arrow

link
brightness_4
code

# R program to create
# quantiles of a data set
# Create a data frame 
d <- data.frame( name = c("Abhi", "Bhavesh", "Chaman", "Dimri"),  
                 age = c(7, 5, 9, 16),  
                 ht = c(46, NA, NA, 69), 
                 school = c("yes", "yes", "no", "no") )
  
# Calling quantile() Function
quantile(d$age)

chevron_right


Output:

   0%   25%   50%   75%  100% 
 5.00  6.50  8.00 10.75 16.00 

Example 2:

filter_none

edit
close

play_arrow

link
brightness_4
code

# R program to create
# quantiles of a data set
  
# Calling pre-defined data set
BOD
  
# Calling quantile() Function
quantile(BOD$demand)
quantile(BOD$Time)

chevron_right


Output:

  Time demand
1    1    8.3
2    2   10.3
3    3   19.0
4    4   16.0
5    5   15.6
6    7   19.8
    0%    25%    50%    75%   100% 
 8.300 11.625 15.800 18.250 19.800 
  0%  25%  50%  75% 100% 
1.00 2.25 3.50 4.75 7.00 
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.