krish

mail@pastecode.io avatar
unknown
plain_text
2 years ago
1.1 kB
0
Indexable
Never
empid=1:15
empid
age=c(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)
status=c(1,1,2,2,1,1,1,2,2,1,2,1,2,1,2)
length(age)
empinfo=data.frame(empid,age,gender,status)
empinfo
empinfo$gender=factor(empinfo$gender,labels=c("male","female"))
empinfo
empinfo$status=factor(empinfo$status,labels=c("staff","faculty"))
empinfo
male=subset(empinfo,empinfo$gender=="male")
male
female=subset(empinfo,empinfo$gender=="female")
female
staff=subset(empinfo,empinfo$status=="staff")
staff
empinfo
faculty=subset(empinfo,empinfo$status=="faculty")
faculty
summary(empinfo)
summary(male)
summary(female)
summary(age)
table1=table(empinfo$gender)
table1
table2=table(empinfo$status)
table2
table3=table(empinfo$gender,empinfo$status)
table3
plot(empinfo$age,type="l",main="Age of employees",xlab="empid",ylab="age in years",col="blue")
pie(table1)
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="o")
boxplot(empinfo$age~empinfo$status,col=c("red","blue"))