 Open in App
Not now

# 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:

 `# 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)) `

Output:

```  min_age
1       5
max_age
1      16
```

Example 2:

 `# 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)) `

Output:

```  mean
1 9.25
med
1   8
```

My Personal Notes arrow_drop_up