Calculate the Median Absolute Deviation in R Programming – mad() Function

mad() function in R Language is used to compute the median absolute deviation i.e. the (lo-/hi-)median of the absolute deviations from the median.

Syntax: mad(x)

Parameters:
x: Vector

Example 1:

filter_none

edit
close

play_arrow

link
brightness_4
code

# R Program to calculate 
# Median Absolute Deviation
  
# Creating a vector
x <- c(1:9)
  
# Calling mad() Function
mad(x)

chevron_right


Output:

[1] 2.9652

Example 2:

filter_none

edit
close

play_arrow

link
brightness_4
code

# R Program to calculate 
# Median Absolute Deviation
  
# Creating a vector
x <- c(1, 4, 2, 3, 7, 3, 8, 9, 2)
  
# Calling mad() Function
mad(x)

chevron_right


Output:

[1] 1.4826
My Personal Notes arrow_drop_up

Check out this Author's contributed articles.

If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.

Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.


Article Tags :

Be the First to upvote.


Please write to us at contribute@geeksforgeeks.org to report any issue with the above content.