R Max and Min

R Max and Min

🔼🔽 R Max and Min

In R, the maximum (max) and minimum (min) values of data are found using the built-in functions max() and min().

These are commonly used in statistics, data analysis, and reporting.


 1. max() – Find Maximum Value


Output:

[1] 40

 2. min() – Find Minimum Value


Output:

[1] 5

 3. Max & Min Together


Output:

[1] 5 40

📌 range() returns min first, then max


 4. Max & Min with Missing Values (NA)

By default, NA gives NA result.


 

❌ Output:

NA

✅ Correct way:



 5. Max & Min in Data Frames


 


 6. Row-wise and Column-wise Max/Min


 


 7. Index of Max & Min Values


✔ Returns position (index) of max/min value


 8. Logical Use Case Example



📌 Summary

  • max() → largest value

  • min() → smallest value

  • range() → min & max together

  • Use na.rm = TRUE to ignore missing values

  • which.max() / which.min() give position

You may also like...