Professional Documents
Culture Documents
----------------------------------------------
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
#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
avg<-mean(newsurvey$Age)
avg
sd<-sd(newsurvey$Height)
sd
var<-var(newsurvey$Height)
var
# 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)