You are on page 1of 2

Ex.

No: 11 MEASURES OF CENTRAL TENDENCY


[DISCRETE DATA]

Problem

Compute the mean, median, mode, geometric mean and harmonic mean for the
following frequency table.

x 2 3 4 5 6 7 8 9 10 11 12
f 1 2 3 4 5 6 5 4 3 2 1

Aim

To find mean, median, mode, geometric mean and harmonic mean for the given data.

Procedure

Step 1: Go to START All programs R Ri386 3.3.2 Open


Step 2: Click FileNew Script
Step 3: Specify given values
Step 4: Finding mean using the formula
Step 5: Median function for finding median
Step 6: Create table and obtain maximum frequency for finding mode.
Step 7: Finding geometric mean using the formula
Step 8: Finding harmonic mean using the formula
Step 9: Click FileSave (to save the coding)
Step 10: Click EditRun all (to run the coding)

R Coding

x<-c(2,3,4,5,6,7,8,9,10,11,12);
cat("x","\n")
x

f<-c(1,2,3,4,5,6,5,4,3,2,1);
cat("f","\n")
f

y1<-rep(x,f);
y1

#Mean
mean<-(sum(y1))/length(y1);
cat("Mean","\n")
mean;

#Median
median<-median(y1);
cat("Median","\n")
median;

#Mode
table(y1)
mode<-names(sort(-table(y1)))[1]
cat("Mode","\n")
mode;

#Geometric Mean
y2=log(x,10)
logg<-sum(f * y2)/sum(f);
gm<-10^logg;
cat("Geometric Mean","\n")
round(gm,2);

#Harmonic Mean
y3=1/x
hm<-sum(f)/sum(f*y3);
cat("Harmonic Mean","\n")
round(hm,2);

Output

x = 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12
f = 1, 2, 3, 4, 5, 6, 5, 4, 3, 2, 1
Mean = 7
Median = 7
Mode = 7
Geometric Mean = 6.52
Harmonic Mean = 5.96

You might also like