Max VS Pmax | Maxium VS Parallel Maxium in R
956 views
May 16, 2024
In this video, we discuss the difference between the max and pmax functions in R. Pmax stands for parallel maximum. Website: thedatahall.com As an Amazon Associate, I earn from qualifying purchases.
View Video Transcript
0:00
Welcome to the Data Hall YouTube channel
0:02
In this video we are going to talk about what is the difference between the max and the
0:06
p max which stands for parallel max functions. So what is the difference between these two functions
0:12
For that let's have two vectors we have this v1 and v2 that contain these two vectors that
0:19
contain certain numbers. Now if we do max v1 what it would do is it would take this vector and get the maximum
0:29
value from it which should be 12. So let me execute this and we see that we get 12 over here
0:37
If I do that for vector 2 we should get 10 because that is the maximum number in this
0:42
v2 vector. Similarly we can have minimum values from both these vectors and both these vectors
0:50
have the minimum value as 1. But what would p max do is instead of getting the maximum value from this vector or from
1:00
this vector or if I were to give them say both these vectors within this this max function
1:10
if we give that both these vectors within this max function what it would do is it would
1:16
get me the maximum number from both of these vectors. But what if I wanted to have a parallel max that means I want to compare this value with
1:26
the first value of the v1 with the first value of the v2 and then I want to get the maximum
1:32
number then I want to do that process similarly for the second value and the third value and
1:39
so forth. So once one way of doing this is to loop through each of these values and loop are an inefficient
1:48
way of performing this. The more efficient way of doing is using the p max
1:53
So what we do is within p max we give both these vectors and it would return the vector
1:59
of the same length so it would compare one the first value of the v1 vector with the
2:06
first value of the v2 vector and it returns us the value 2 then it would do that for the
2:12
second value the third value and so on and so forth. If we just give them a single vector then it would return that specific vector because
2:23
that is the maximum value. We can similarly do minimum p minimum and that will return the minimum value between
2:32
these two vectors. Now what if we have a vector of different length and what if we have some missing values
2:39
within these vectors. So this is a vector of the same vector as we had over here but we have shortened the
2:47
length of v2 and we have also included in Na missing value within this v2
2:54
So let me redefine v1 and v2 and now if we do p max firstly it would give us a warning
3:00
that we that the second the smaller vector had been recycled that is the that is the
3:09
by default system of R that it recycles the smaller vector and at the same time it would
3:18
give us the Na value within because it when it compares the Na with some other digit it
3:25
would return us the Na value. So what if first of all I wanted to remove the Na values so what I do is I use the Na
3:35
dot rm equal to true argument and that would remove the Na values right and it would not
3:43
take into consideration the Na values. So I hope that was useful
3:48
Do subscribe to this channel and do hit the bell icon
#Computer Education
#Educational Software
#Other