You are on page 1of 10

LAB - 8

Name: Sam Melvin M Course: FDA

Reg no: 19MIS1106 Course Code: CSE3505

----------------------------------------------

PART-A
#Use the newsurvey data obtained by cleaning ‘na’ values in survey data of
MASS package to do the following:
library(MASS) #Import the package MASS.
Survey
#Create a data frame ‘newsurvey’ that contains the survey data after
removing the na values
newsurvey<-data.frame(na.omit(survey))
newsurvey
#1)Find the range of students’ age participated in the survey.
r<-range(newsurvey$Age)
r

#2)Break the age range into non-overlapping sub-intervals by defining a


sequence of equal distance break points of 10 by rounding the range to
nearest integer.
#seq(16.917,70.417,10)#b<-round(seq(16.917,70.417,10),0)#b
c2<-ceiling(r[2])
c1<-floor(r[1])
if((c2-c1)%/%10!=0)
{
c2<-c2+10
}
b1<-seq(c1,c2,10)
b1
cut(newsurvey$Age,b1,right=FALSE)
#cut(round(newsurvey$Age,0),breaks = 10)

#3)Find the distribution of the age range according to the sub-intervals with
cut with its right boundary opened. Display it in column form.
i1<-cut(newsurvey$Age,b1,right=FALSE)
t1<-data.frame(table(i1))
t1

#4)Which age range of students has mostly participated in the survey.


t1[which.max(t1$Freq),1]
#5)Similarly, find the frequency distribution of Wr.Hnd span and display it in
column format.
f<-table(newsurvey$Wr.Hnd)
f_dis<-data.frame(f)
f_dis

#6)Find the relative frequency of Wr.Hnd and display it by correcting to 3


decimal places.
round(prop.table(newsurvey$Wr.Hnd),3)
PART – 2
# 1. Find the average age of the students participated in the survey.

avg<-mean(newsurvey$Age)
avg

# 2. Compute the standard deviation and variance of the height of the


students participated in the survey.

sd<-sd(newsurvey$Height)
sd

var<-var(newsurvey$Height)
var

# 3. Compute the quartile of write hand span.

quartile<-quantile(newsurvey$Wr.Hnd, probs = c(0,0.25,0.5,0.75,1))


quartile

# 4. Find the correlation between write hand span and pulse rate of the
students.

correlation <-cor(newsurvey$Wr.Hnd,newsurvey$Pulse)
correlation

# 5. Find the average age of the students based on how often the student
exercises.

#Sometimes Exercise
library(dplyr)
some<-newsurvey$Exer=='Some'
some
avg1<-mean(some)
avg1

#Frequently Exercise
frequently<-newsurvey$Exer=='Freq'
frequently
avg2<-mean(frequently)
avg2
#6 Find the standard deviation of height of the students under different
categories of span of non-writing hand.

Right<-filter(newsurvey, newsurvey$W.Hnd=='Right')
Right
Left<-filter(newsurvey, newsurvey$W.Hnd=='Left')
Left
SDR<- sd(Right$Height)
SDR
SDL<- sd(Left$Height)
SDL
#7 Obtain the summary statistics of pulse rate of the students.

summary(newsurvey$Pulse)

You might also like