The R max function returns the maximum value of a vector or column. The R min function returns the minimum value of a vector or column. The basic R code for the max and min functions is shown above. The most basic usage of max and min is their application to a numeric vector. Our example vector consists of five numbers, stored in the data object x1. By the way: I have also recorded a video containing Examples 1 and 2 of this tutorial.
You can check out the video tutorial here:. Please accept YouTube cookies to play this video. By accepting you will be accessing content from YouTube, a service provided by an external third party.
YouTube privacy policy. Accept YouTube Content. As you have seen in the video, there might occur complications when we have NA values. You can find the code of the second example of the video in the following…. A problem can occur, when your data contains NA values i. Our new example vector looks exactly as in Example 1, but this time with an NA value at the end. Just specify the option na. But what if we want to apply max and min to a column of a data frame?
The data can be loaded with the following R code:. Table 1: The mtcars Data as Example data. You might be interested in the maxima and minima of all the columns of your data matrix. Of cause, you could apply the max and min R functions to each of the columns one by one. However, the sapply function provides a much smoother and automatized way to calculate all maxima and minima with one line of code.
You want to know the maximum and minimum of the whole data set? So be it…. Improve this question. Omar Wagih Omar Wagih 7, 6 6 gold badges 56 56 silver badges 74 74 bronze badges.
Add a comment. Active Oldest Votes. Improve this answer. Jouni Helske Jouni Helske 6, 27 27 silver badges 50 50 bronze badges. Benchmarking is beautiful! Thank you, I think I'll go with option 2! You could reverse x which. DWin, is there a difference in setting arr. I don't think so. I probably should just have used which. Sometimes I over-think. BobbyBean BobbyBean 31 2 2 bronze badges.
Sign up or log in Sign up using Google. Sign up using Facebook. Sign up using Email and Password. Post as a guest Name. Email Required, but never shown. The Overflow Blog. Does ES6 make JavaScript frameworks obsolete?
0コメント