setwd("~/R")
dean.df<-read.csv(paste("Data - Deans Dilemma.csv",sep=""))
  1. Use R to calculate the median salary of all the students in the data sample.
median(dean.df$Salary)
## [1] 240000
  1. Use R to calculate the percentage of students who were placed, correct to 2 decimal places.
sum(dean.df$Placement_B==1)/nrow(dean.df)*100
## [1] 79.7954
  1. Use R to create a dataframe called placed, that contains a subset of only those students who were successfully placed.
placed<-dean.df[which(dean.df$Placement_B==1),]
  1. Use R to find the median salary of students who were placed.
median(placed$Salary)
## [1] 260000
  1. Use R to create a table showing the mean salary of males and females, who were placed.
mytable<-aggregate(dean.df$Salary,list(dean.df$Gender),mean)
View(mytable)
  1. Use R to generate the following histogram showing a breakup of the MBA performance of the students who were placed.
hist(dean.df$Percent_MBA,main = "MBA Performance of placed students",xlab = "MBA Percentage",ylab="Count",ylim=c(0,200),xlim=c(50,80),breaks=3,col="lightblue")

  1. Create a dataframe called notplaced, that contains a subset of only those students who were NOT placed after their MBA.
notplaced<-dean.df[which(dean.df$Placement_B==0),]
View(notplaced)
  1. Draw two histograms side-by-side, visually comparing the MBA performance of Placed and Not Placed students.
par(mfrow=c(1,2))
hist(placed$Percent_MBA,main="MBA Performance of placed students",xlab ="MBA Percentage",ylab = "Count",breaks = 3)
hist(notplaced$Percent_MBA,main="MBA Performance of not placed students",xlab ="MBA Percentage",ylab = "Count",breaks = 3)

par(mfrow=c(1,1))
  1. Use R to draw two boxplots, one below the other, comparing the distribution of salaries of males and females who were placed.
#par(mfrow=c(2,1))
boxplot(placed$Salary~placed$Gender,yaxt="n",horizontal = TRUE,main="Comparison of Salaries of Males and Females",xlab="Salary",ylab="Gender")
axis(side=2,at=c(1,2),labels = c("Females","Males"))

  1. Create a dataframe called placedET, representing students who were placed after the MBA and who also gave some MBA entrance test before admission into the MBA program.
placedET<-dean.df[which(dean.df$Placement_B==1&dean.df$S.TEST==1),]
library(car)
scatterplotMatrix(~placedET$Salary+placedET$Percent_MBA+placedET$Percentile_ET,diagonal="density",cex=0.6)