Professional Documents
Culture Documents
Muthayammal College of Arts and Science Rasipuram: Assignment No - 3
Muthayammal College of Arts and Science Rasipuram: Assignment No - 3
Rasipuram
Assignment No - 3
Name : K.Haritha
Roll no : 21UST004
Date :
K.Haritha
PROGRAM
# Defining vector
x <- c(3, 7, 5, 13, 20, 23, 39, 23, 40, 23, 14, 12, 56, 23)
# Print mean
print(mean(x))
OUTPUT
21.5
MEDIAN
In R, the median() function is used to calculate the median, which is another measure
of central tendency. The median is the middle value of a dataset when it is ordered. If the
dataset has an odd number of observations, the median is the middle value. If the dataset has
an even number of observations, the median is the average of the two middle values.
PROGRAM
# Defining vector
# Print Median
median(x)
OUTPUT
21.5
MODE
The mode of a given set of values is the value that is repeated most in the set. There
can exist multiple mode values in case there are two or more values with matching maximum
frequency.
PROGRAM
# vector of marks
marks <- c(97, 78, 57,78, 97, 66, 87, 64, 87, 78)
mode = function() {
return(names(sort(-table(marks)))[1])
mode()
OUTPUT
78
2.MEASURES OF DISPERSION
RANGE
We can find the minimum and the maximum of a vector using the min() or the max()
function. A function called range() is also available which returns the minimum and
maximum in a two element vector
PROGRAM
print(data_range)
OUTPUT
1 10
VARIANCE
Variance is the sum of squares of differences between all numbers and means. The
mathematical formula for variance is as follows, where, N is the total number of elements or
frequency of distribution. The variance can calculate by using var() function in R.
PROGRAM
list = c(2, 4, 4, 4, 5, 5, 7, 9)
print(var(list))
OUTPUT
4.571429
STANDARD DEVIATION
PROGRAM
# R program to get
list = c(2, 4, 4, 4, 5, 5, 7, 9)
# Calculating standard
print(sd(list))
OUTPUT
2.13809
3.SKEWNESS
PROGRAM
# install.packages("e1071")
library(e1071)
# Calculate skewness
print(paste("Skewness:", skew_value))
OUTPUT
-0.317740168714651"
KURTOSIS
PROGRAM
# install.packages("moments")
library(moments)
# Calculate kurtosis
print(paste("Kurtosis:", kurtosis_value))
OUTPUT
2.256