VOOZH about

URL: https://www.geeksforgeeks.org/r-language/get-max-value-of-column-by-group-in-r/

⇱ Get max value of column by group in R - GeeksforGeeks


  • Courses
  • Tutorials
  • Interview Prep

Get max value of column by group in R

Last Updated : 23 Jul, 2025

In this article, we will explore various methods to get the maximum value of a column by group using the R Programming Language.

How to get the maximum value of the column by group

R language offers various methods to get the maximum value of the column by the group. By using these methods provided by R, it is possible to get the maximum value of the column. Some of the methods to get the maximum value of the column are:

Get the max value of the column by group using Base R

This method is used to get the maximum value of the column by group using Base R. In this example, we created a data frame and found the maximum value of a column.

Output:

 name age
1 a 1
2 a 2
3 b 3
4 b 4
5 b 5
6 c 6
7 c 7
8 d 8

[1] "The maximum value of column by group is"
name age
1 a 2
2 b 5
3 c 7
4 d 8

In this example, we created a data frame and finded the maximum value of a column.

Output:

 student id
1 m 601
2 n 602
3 n 603
4 o 604
5 o 605
6 m 606

[1] "The maximum value of column by group is"
student id
1 m 606
2 n 603
3 o 605

Get maximum value of column by using the package 'dplyr'

This method is used to get maximum value of column by group using the package dplyr. In this example, we created a data frame and finded the maximum value of a column.

Output:

 group value
1 A 10
2 A 20
3 B 15
4 B 25
5 C 5
6 C 10

A tibble: 3 × 2
group max_value
<chr><dbl>
1 A 20
2 B 25
3 C 10

In this example, we created a data frame and finded the maximum value of a column.

Output:

 student id
1 m 5
2 n 6
3 o 7
4 q 8
5 q 9
6 m 10
7 s 11
8 s 12

A tibble: 5 × 2
student max_value
<chr><int>
1 m 10
2 n 6
3 o 7
4 q 9
5 s 12

Conclusion

In conclusion, we learned about how to get maximum value of column by group using various methods. R provides versatile tools to get maximum value of column by group efficiently.

Comment
Article Tags:

Explore