...

Artificial Intelligence - R Programming Advanced

Back to Course

Lesson Description


Lession - #962 R Median


Median
The median value is the value in the middle, after you have sorted all the values.
If we take a look at the values of the
wt
variable (from the
mtcars
data set>
, we will see that there are two numbers in the middle:
Sorted observation of wt (weight>
1.513 1.615 1.835 1.935 2.140 2.200 2.320 2.465
2.620 2.770 2.780 2.875 3.150 3.170 3.190 3.215
3.435 3.440 3.440 3.440 3.460 3.520 3.570 3.570
3.730 3.780 3.840 3.845 4.070 5.250 5.345 5.424

Luckily, R has a function that does all of that for you: Just use the
median(>
function to find the middle value:

Example

Find the mid point value of weight (
wt

Data_Cars <- mtcars

median(Data_Cars$wt>
Result:

  [1] 3.325