How to find the maximum value in an R data frame?

The maximum value is a part of summary statistics and we always need to understand the end limits of our data; therefore, it is highly required. If we have a data frame that contains numerical columns then the maximum value can be found by using max function and the data frame object name.

Example1

y1<−rexp(20,2.24)
y2<−runif(20,2,10)
y3<−rpois(20,2)
df2<−data.frame(y1,y2,y3)
df2

Output

      y1       y2      y3
1 0.407887709 2.213538 1
2 1.740076315 8.314833 3
3 0.192889321 2.085092 1
4 0.166686518 2.295179 3
5 0.057761320 3.117768 5
6 0.001199064 8.917747 3
7 0.212810013 5.560138 1
8 0.295809473 6.418326 0
9 0.198128409 6.662312 3
10 0.711248734 4.899675 2
11 0.228512534 5.439995 1
12 0.614415810 7.231990 2
13 0.552638453 6.999130 3
14 1.181955638 2.650087 3
15 0.094478314 4.154438 4
16 0.114416419 2.687630 3
17 0.521020383 4.552469 2
18 0.145134708 3.100630 1
19 0.189475950 3.741155 1
20 0.055434073 7.268179 3

Finding the maximum value in df2 −

Example

max(df2)

Output

[1] 8.917747

Example3

z1<−rnorm(20)
z2<−rnorm(20)
z3<−rnorm(20)
df3<−data.frame(z1,z2,z3)
df3

Output

      z1          z2          z3
1 0.25666831 −0.01903028   0.6416281
2 0.37078975 −0.88863057   1.3649943
3 0.75034126 1.78456003   −1.3705236
4 −1.17411909 −0.17708087  0.4413502
5 −0.51917037 2.70309602   0.6068021
6 −0.06786451 0.97958347   0.3195107
7 −0.45662528 0.31657666   1.4426260
8 0.06079389 0.59762732    1.8300967
9 0.32373216 −0.48484042   0.5149204
10 −0.80419025 −1.41713258 0.3394880
11 0.05776455 −0.08407858 −0.5394629
12 −0.98194207 −0.79692879 0.2427494
13 0.37626316 0.92851151   0.3595236
14 −0.51862537 −0.68906500 1.5214189
15 0.47366488 1.59535911   0.8477736
16 1.07751737 1.59310361  −1.6904989
17 −1.61338456 −0.87773672 −0.3547148
18 −1.53023659 0.70204809   1.1185562
19 −0.17439684 0.29133043  −0.1620996
20 −1.31023224 −0.94650432 −0.5271143

Example

Finding the maximum value in df3 −

max(df3)

Output

[1] 2.703096
Updated on: 2026-03-11T22:50:55+05:30

2K+ Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements