Find the index of the maximum value in R DataFrame Last Updated : 11 Nov, 2022 Comments Improve Suggest changes Like Article Like Report In this article, we will see how to find the index of the maximum value from a DataFrame in the R Programming Language We can find the maximum value index in a dataframe using the which.max() function. Syntax: which.max(dataframe_name$columnname) "$" is used to access particular column of a dataframe. Given below are various implementations, depicting various datatypes and situations to help you understand better. Example 1: R # vector 1 data1=c("sravan","bobby","pinkey","rohith","gnanesh") # vector 2 data2=c(98,78,79,97,89) # creating a dataframe with names and marks # using above vectors final <- data.frame(names=data1,marks=data2) print(final) # display the maximum value index in 2 nd column # (marks column) in a dataframe print(paste("highest index is : ",which.max(final$marks))) Output: If there is more than one maximum value, then it will return index of first number which is repeated. Example 2: R # vector 1 data1=c("sravan","bobby","pinkey","rohith", "gnanesh",'divya',"satwik","chandu") # vector 2 data2=c(98,78,79,97,89,89,99,99) # creating a dataframe with names and marks # using above vectors final <- data.frame(names=data1,marks=data2) print(final) print(paste("highest index is : ",which.max(final$marks))) Output: If the data is of type character, it will find the maximum value using ASCII values. Example 3: R # vector 1 data1=c("sravan","bobby","pinkey","rohith", "gnanesh",'divya',"satwik","zhandu") # vector 2 data2=c(98,78,79,97,89,89,99,99) # creating a dataframe with names and marks # using above vectors final <- data.frame(names=data1,marks=data2) print(final) # display maximum value index for character values print(paste("highest index is : ",which.max(final$names))) Output: Example 4: R # vector 1 that contains NA values as characters data1=c(NA,"sravan",NA,NA,NA) # vector 2 contains all data data2=c(102,98,98,102,102) # creating a dataframe with names and marks # using above vectors final <- data.frame(names=data1,marks=data2) print(final) # display maximum value index for character values print(paste("highest index is : ",which.max(final$names))) # display maximum value index for marks values print(paste("highest index is : ",which.max(final$marks))) Output: If row containing all the values are same so all are higher. So it will return index of first element. Example 5: R # vector contains all same data data2=c(102,102,102,102,102) # creating a dataframe marks using above vector final <- data.frame(marks=data2) print(final) # display maximum value index for marks values print(paste("highest index is : ",which.max(final$marks))) Output: If the data contains values as NA, then it will return empty. Example 6: R # vector contains all NA's data2=c(NA,NA) # creating a dataframe marks using # above vector final <- data.frame(marks=data2) print(final) # display maximum value index for marks values print(paste("highest index is : ",which.max(final$marks))) Output: Comment More infoAdvertise with us Next Article Find the index of the maximum value in R DataFrame gottumukkalabobby Follow Improve Article Tags : R Language R Programs R-DataFrame R DataFrame-Programs Similar Reads How to extract the dataframe row with min or max values in R ? The tabular arrangement of rows and columns to form a data frame in R Programming Language supports many ways to access and modify the data. Application of queries and aggregate functions, like min, max and count can easily be made over the data frame cell values. Therefore, it is relatively very ea 5 min read How to find the sum of column values of an R dataframe? In this article, we are going to find the sum of the column values of a dataframe in R with the use of sum() function. Syntax: sum(dataframe$column_name) Creating a Dataframe A dataframe can be created with the use of data.frame() function that is pre-defined in the R library. This function accepts 2 min read Add Index ID to DataFrame in R In this article, we will discuss how index ID can be added to dataframes in the R programming language. Method 1 : Using cbind() and nrow() methods The nrow() method in R Programming language is used to compute the number of rows in the dataframe that is specified as an argument of this method. cbi 5 min read How to find Mean of DataFrame Column in R ? In this article, we will discuss how to compute the mean of the Dataframe Column in R Programming language. It can be done in various ways: Using $-OperatorUsing [[]]Using Column IndexUsing summarise function of the dplyr PackageUsing colMeans Function Method 1: Using $-Operator. This is one of the 5 min read Finding the maximum value in a vector using a for loop? In this article, we will discuss how to find the maximum value in a vector with its working example in the R Programming Language using R for loop. In R programming, loops are essential constructs that allow us to repeat a set of instructions multiple times. The for loop is one such construct that r 4 min read Select Rows if Value in One Column is Smaller Than in Another in R Dataframe In this article, we will discuss how to select rows if the value in one column is smaller than another in dataframe in R programming language. Data frame in use: Method 1: Using Square Brackets By using < operator inside the square bracket we can return the required rows. Syntax: dataframe[datafr 2 min read Return Column Name of Largest Value for Each Row in R DataFrame In this article, we will discuss how to return column names of the largest value for each row in DataFrame in R Programming Language. Example:  Column1Column2Column3Max columnRow1200Column1 , Because,  Column2 value and Column 3 value is less than Column1Row2435Column3 , Because,  Column2 value and 2 min read Find the Nth highest value of a vector in R In this article, we will see how to find the Nth largest value of a vector in the R Programming Language. Steps for finding nth largest element in vector R: Step 1: Create a vector and take input from the user. Syntax : variable name = readline() Where Variable is the valid identifier. readline() w 3 min read How to get the structure of a given DataFrame in R? In this article, we will see how to get the structure of a DataFrame in R programming. Structure of a dataframe generally means the inner details about the dataframe. Steps for Getting Structure of DataFrame: Create dataframe.The size of each vector should be the same.Follow the syntax while creatin 2 min read Select First Row of Each Group in DataFrame in R In this article, we will discuss how to select the first row of each group in Dataframe using R programming language. The duplicated() method is used to determine which of the elements of a dataframe are duplicates of other elements. The method returns a logical vector which tells which of the rows 2 min read Like