Condense Column Values of a Data Frame in R Programming – summarise() Function
Last Updated :
19 Jun, 2020
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:
library(dplyr)
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" ) )
summarise(d, min_age = min (age))
summarise(d, max_age = max (age))
|
Output:
min_age
1 5
max_age
1 16
Example 2:
library(dplyr)
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" ) )
summarise(d, mean = mean(age))
summarise(d, med = median(age))
|
Output:
mean
1 9.25
med
1 8
Like Article
Suggest improvement
Share your thoughts in the comments
Please Login to comment...