How to measure the central tendency of the given data using R?

Description

To measure the central tendency of the given data in R programming.

Measures of central tendency

  • Mean
  • Median
  • Mode

1) Mean:

  • Mean is the average of the data set.
  • It is applicable only to numerical values.
  • R Function : mean()

2) Median:

  • Median the center value of the data set.
  • It is applicable only to numerical value.
  • R Function : median()

3) Mode:

  • Mode is the highest occurrences value.
  • It is applicable to both numerical and character type
  • No inbuilt function to find mode value in R

#Measure of Central tendency

#Read File
print(getwd())
setwd(“/home/soft13″)
print(getwd())
data<-read.csv(‘input.csv’)
print(data)
print(is.data.frame(data))

#Mean

mean(data$salary)

#Median
median(data$salary)

#Mode
mode<-function(f){
uniq<-unique(f)
uniq[which.max(tabulate(match(f,uniq)))]
}
mode(data$salary)
mode(data$dept)

#Summary
summary(data)

Leave Comment

Your email address will not be published. Required fields are marked *

clear formSubmit