0% found this document useful (0 votes)
41 views

Experiment Lab-II

This document describes experiments to represent data using tables and graphs for summary statistics. It includes creating vectors for employee data, combining the vectors into a data frame, and performing summary statistics and graphical representations. Specifically, it generates summary statistics, one-way and two-way tables, plots, pie charts, bar plots, and boxplots for the employee and life satisfaction datasets to analyze characteristics by factors like gender, status, smoking status and more. It also provides an example for students to create their own dataset and analyze it.

Uploaded by

Chutiya
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
41 views

Experiment Lab-II

This document describes experiments to represent data using tables and graphs for summary statistics. It includes creating vectors for employee data, combining the vectors into a data frame, and performing summary statistics and graphical representations. Specifically, it generates summary statistics, one-way and two-way tables, plots, pie charts, bar plots, and boxplots for the employee and life satisfaction datasets to analyze characteristics by factors like gender, status, smoking status and more. It also provides an example for students to create their own dataset and analyze it.

Uploaded by

Chutiya
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 9

Experiment Lab-II

Computation of tables and graphs-summary statistics


Aim: To represent the various types of data using tabulation
and graphical representation

Question No1:-Computation of tables and graphs-summary statistics for


employee data

Creating vector:-

>empid=c(1,2,3,4,5,6,7,8,9,10,11,12,13,14,15) #creating a vector empid

> empid

[1] 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15

> age=c(30,37,45,32,50,60,35,32,34,43,32,30,43,50,60)

# creating a vector age

> age

[1] 30 37 45 32 50 60 35 32 34 43 32 30 43 50 60

> sex=c(0,1,0,1,1,1,0,0,1,0,0,1,1,0,0)

> sex

[1] 0 1 0 1 1 1 0 0 1 0 0 1 1 0 0

> status=c(1,1,2,2,1,1,1,2,2,1,2,1,2,1,2)

> status

[1] 1 1 2 2 1 1 1 2 2 1 2 1 2 1 2

Creating a data frame (Combining vectors):

> empinfo=data.frame(empid,age,sex,status)
> empinfo

> empinfo$sex=factor(empinfo$sex,labels=c("male","female"))

> empinfo$status=factor(empinfo$status,labels=c("staff","faculty"))

>empinfo

#The following command shows male data only


#The following command shows female data only

? Similarly create staff data set and faculty dataset

 Summary statistics for empinfo data

 Summary statistics for male and female employees data


 Summary statistics for age

> summary(empinfo$age)
Min. 1st Qu. Median Mean 3rd Qu. Max.
30.00 32.00 37.00 40.87 47.50 60.00

 Creating one-way table


1. For sex

2. For status

 Creating two-way table


Gaphical reperesentation in R

>plot(empinfo$age,type="l",main="age of
subjects",xlab="empid",ylab="age in years",col="blue")

Pie Chart:-

> table4<-table(empinfo$sex)
> pie(table4)
> table5=table(empinfo$sex,empinfo$status)

> barplot(table5,beside=T,xlim=c(1,15),ylim=c(0,5))

>legend("topright",legend=rownames(table5),fill=c('blue','red'),bty="n")

bty the type of box to be drawn around the legend. The allowed
values are "o" (the default) and "n".
BOXPLOT:-

 boxplot(empinfo$age~empinfo$status,col=c("red","blue"))

Question2 :-( Life satisfaction data)

#downloading the Raw data into R

 Life_Data<-read.csv("C:\\Users\\aadmin\\Desktop\\mokesh\\data1.csv")

read.
# Printing the data

>Life__Data

#checking the summary statistics of the continues variables

>summary(Life_Data$IncomeC)

>summary(Life_Data$Income)

# creating labels

>Life_Data$Gender=factor(Life_Data$Gender,labels=c("male","female"))

>Life_Data$Married=factor(Life_Data$Married,labels=c("no","yes"))

>Life_Data$Smoke=factor(Life_Data$Smoke,labels=c("no","yes"))

>Life_Data$Finish=factor(Life_Data$Finish,labels=c("no","yes"))

#checking the Frequency of the discrete variables

table(Life_Data$Age)

table(Life_Data$Gender)

table(Life_Data$Married)

table(Life_Data$Smoke)

table(Life_Data$Finish)

#generating cross tabulations

table(Life_Data$Gender,Life_Data$Married)

table(Life_Data$Gender,Life_Data$Finish)

table(Life_Data$Gender,Life_Data$Finish,Life_Data$Married)

table(Life_Data$LifeSat,Life_Data$Smoke)
#generating Graphs

counts <- table(Life_Data$LifeSatC )

barplot(counts, main="Lift Satisfaction Distribution",xlab="Score on Life


Satisfaction",)

Question 3: Challenging Experiment

Create your own (Student Record) dataset and do the summary statistics
and graphs with interpretation. Use atleast 50 observations with five
variables.

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy