How would you find the max or min value in each column or row of a matrix or data frame in R?

  • Use the apply() function with the appropriate margin argument
  • Use the max() or min() function with the appropriate argument
  • Use the colMax() or rowMax() function for matrices
  • Use the max.col() or min.col() function for data frames
To find the max or min value in each column or row of a matrix or data frame in R, you can use the apply() function. By specifying the appropriate margin argument (1 for rows, 2 for columns), you can apply the max() or min() function across the specified dimension.
Add your answer
Loading...

Leave a comment

Your email address will not be published. Required fields are marked *