Condense Column Values of a Data Frame in R Programming – summarise() Function

summarise() function in R Language is used to condense various values of column of a data frame to one value.

Syntax: summarise(x, expr)

Parameters:
x: Data Frame
expr: Operation to condense data

Example 1:

filter_none

edit
close

play_arrow

link
brightness_4
code

# R program to condense data
# of a data frame
  
# Loading library 
library(dplyr)
    
# 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") ) 
  
# Calculating min age 
summarise(d, min_age = min(age)) 
    
# Calculating max age 
summarise(d, max_age = max(age)) 

chevron_right


Output:

  min_age
1       5
  max_age
1      16

Example 2:

filter_none

edit
close

play_arrow

link
brightness_4
code

# R program to condense data
# of a data frame
  
# Loading library 
library(dplyr)
    
# 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") ) 
  
# Calculating mean of age 
summarise(d, mean = mean(age)) 
  
# Calculating median of age 
summarise(d, med = median(age)) 

chevron_right


Output:

  mean
1 9.25
  med
1   8



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.