Summarise

The summarise verb is used to obtain aggregate values, generally over a grouped variable.

The following highlights some of the common operations using summarise. Generally, summarise is preceded by a group_by operation, that is, the summary is performed over grouped variables, as shown:

# In the example below: # 1) We sorted the DataFrame by State Name using arrange # 2) We applied a group-by using Region, i.e., all resulting values would be aggregated using Region # 3) We calcuated the values for total rows using n(), the unique states belonging to each region using n_distinct # the max & mean literacy using max and mean respectively # tstate %>% arrange(Name) %>% group_by(Region) %>% summarise(total_rows = n(), first_state = first(Name), ...

Get Hands-On Data Science with R now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.