Experiment 2
Experiment 2
Procedure:
Step by step procedure to conduct the required experiment –
1. Arrangement of data using various R functions
2. Visualize the data set using various R functions
Code and Results:
empid=c(1,2,3,4,5,6,7,8,9,10,11,12,13,14,15)
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)
age
## [1] 30 37 45 32 50 60 35 32 34 43 32 30 43 50 60
gender=c(0,1,0,1,1,1,0,0,1,0,0,1,1,0,0)
gender
## [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
## [1] male female male female female female male male female male
## [11] male female female male male
## Levels: male female
empinfo$status=factor(empinfo$status,labels=c("staff","faculty"))
empinfo$status
empinfo
## empid age gender status
## 1 1 30 male staff
## 2 2 37 female staff
## 3 3 45 male faculty
## 4 4 32 female faculty
## 5 5 50 female staff
## 6 6 60 female staff
## 7 7 35 male staff
## 8 8 32 male faculty
## 9 9 34 female faculty
## 10 10 43 male staff
## 11 11 32 male faculty
## 12 12 30 female staff
## 13 13 43 female faculty
## 14 14 50 male staff
## 15 15 60 male faculty
# Extract male data
male=subset(empinfo,empinfo$gender=="male") male
summary(female)
## empid age gender status
## Min. : 2.000 Min. :30.00 male :0 staff :4
## 1st Qu.: 4.500 1st Qu.:33.00 female:7 faculty:3
## Median : 6.000 Median :37.00
## Mean : 7.286 Mean :40.86
## 3rd Qu.:10.500 3rd Qu.:46.50
## Max. :13.000 Max. :60.00
summary(age)
## Min. 1st Qu. Median Mean 3rd Qu. Max.
## 30.00 32.00 37.00 40.87 47.50 60.00
##
## male female
## 8 7
table2=table(empinfo$status) table2
##
## staff faculty
## 8 7
##
## staff faculty
## male 4 4
## female 4 3
plot(empinfo$age,type="l",main="Age
of employees",xlab="empid",ylab="age in
pie(table1)
# Graphical representation (Bar plot)
barplot(table3,beside=T,xlim=c(1,15),ylim=c(0,5),col=c("blue", "red"))
legend("topright",legend=rownames(table3),fill=c('blue','red'),bty="n")