Ungroup()
function in R programming is used in data management. It is used to ungroup the data from its grouped form. It is always used after the group()
function. But remember to always use ungroup()
function after the execution of code.
Syntax
ungroup()
Parameters
There are no parameters.
Return value
The grouped data as ungroup form.
Explanation
library("dplyr")
#Given data is grouped here
group_by(gender)
#Calculates the average age of boys and girls
#mutate() function is used to add columns in given data
mutate(boys = mean(age))
#get mean score
mutate(x = mean(score))
#Close the group
ungroup()
- Line#2: it will group the data by gender.
- Line#6: Using
mutate()
method to get the mean of the age of boys in the data. - Line#8: It’ll return the mean score of students.
- Line#10: Using the
ungroup()
function to ungroup the data.