Mean, Median, Mode in R - Central Tendency


Mean, Median, Mode in R - Central Tendency

x <- c(1,2,3,4,5,6,7,7,7)

# calculate mean
mean(x) 
4.666667

# calculate median
median(x)
5

# calculate mode
tbl(x)
1 2 3 4 5 6 7 
1 1 1 1 1 1 3 

#mode == 7 as it is present 3 times


Remember
1. # is used to comment in R and will not execute
2. Ctrl + Enter will executed the code in line where the cursor is. No need to select the code.
3. Mean == average
4. Median == Middle value in a sorted data set
5. Mode == Most common observation

# calculate standard deviation # post your results if you found this useful
sd(x)



# calculate variance # post your result if you found this useful
var(x)

# calculate IQR (interquartile range)
IQR(x)


Comments