Get Maximum value of a column in R

Maximum value of a column in R can be calculated by using max() function. Let’s see how to calculate Maximum value in R with an example.

Let’s first create the dataframe.

### Create Data Frame
df1 = data.frame(Name = c('George','Andrea', 'Micheal','Maggie','Ravi','Xien','Jalpa'), 
                 Grade_score=c(4,6,2,9,5,7,8),
                 Mathematics1_score=c(45,78,44,89,66,49,72),
                 Science_score=c(56,52,45,88,33,90,47))
df1

So the resultant dataframe will be

Get maximum value of a column in R 1

 

Get Maximum value of the column in R

Method 1:

Get Maximum value of the column by column name

# Get Maximum value of the column by column name

max(df1$Mathematics1_score)

Result:

[1] 89

 

Method 2:

Get Maximum value of the column by column position

# Get Maximum value of the column by column position

max(df1[,3])

Result:

[1] 89