从R中的数据图中查找百分比

从R中的数据图中查找百分比,r,R,我正在与第1G部分作斗争。 我使用了dput(),这是用于此问题的部分数据: paiddeposit=c(1L, 0L,1L,1L,0L,0L,1L,1L,1L,1L,0L,0L,0L,0L,0L,0L,0L,0L, 1L,1L,0L,0L,1L,1L,0L,0L,0L,1L,0L,1L,0L,1L,0L,1L,0L,0L,0L, 0L、1L、0L、0L、0L、1L、0L、1L、0L、1L、0L、0L、1L、0L、1L、0L、0L、0L、1L、, 0L,0L,0L,0L,0L,0L,0L,1L,

我正在与第1G部分作斗争。 我使用了dput(),这是用于此问题的部分数据:

paiddeposit=c(1L, 0L,1L,1L,0L,0L,1L,1L,1L,1L,0L,0L,0L,0L,0L,0L,0L,0L, 1L,1L,0L,0L,1L,1L,0L,0L,0L,1L,0L,1L,0L,1L,0L,1L,0L,0L,0L, 0L、1L、0L、0L、0L、1L、0L、1L、0L、1L、0L、0L、1L、0L、1L、0L、0L、0L、1L、, 0L,0L,0L,0L,0L,0L,0L,1L,0L,0L,0L,0L,0L,0L,0L,0L,0L,0L,0L,0L, 0L,1L,0L,0L,0L,1L,0L,0L,0L,1L,0L,0L,0L,0L,0L,0L,1L,0L, 0L,0L,0L,0L,0L,1L,0L,0L,0L,1L,0L,0L,0L,0L,0L,0L,1L,0L, 0L、1L、0L、0L、0L、0L、0L、0L、0L、0L、0L、0L、0L、0L、0L、1L、0L、, 1L,0L,0L,0L,0L,1L,0L,1L,0L,0L,0L,0L,0L,1L,0L,0L,0L, 0L、0L、0L、0L、0L、0L、0L、0L、0L、0L、0L、0L、0L、1L、1L、0L、0L、0L、, 1L,0L,0L,0L,1L,1L,0L,0L,0L,0L,1L,1L,0L,0L,0L,0L,0L,0L,0L,1L, 1L、1L、0L、1L、0L、0L、0L、0L、0L、1L、0L、0L、0L、0L、0L、1L、1L、, 0L,1L,0L,1L,1L,1L,0L,0L,0L,1L,0L,1L,1L,0L,0L,0L,0L, 0L,0L,0L,0L,0L,1L,0L,0L,0L,0L,0L,0L,0L,0L,0L,0L,0L,0L,0L,0L, 0L、0L、0L、1L、0L、1L、0L、1L、1L、0L、1L、1L、0L、1L、0L、1L、0L、0L、0L、0L、, 0L,0L,0L,0L,0L,0L,0L,0L,0L,0L,0L,1L,1L,1L,0L,0L, 0L,0L,0L,0L,0L,0L,0L,0L,0L,1L,0L,0L,0L,0L,0L,0L,0L,0L,0L, 0L,0L,1L,1L,0L,0L,1L,0L,0L,1L,0L,0L,0L,1L,0L,0L,0L, 0L、1L、0L、0L、0L、1L、0L、0L、1L、0L、0L、0L、0L、0L、0L、0L、0L、0L、0L、0L、, 1L、0L、0L、1L、0L、0L、1L、0L、0L、1L、0L、0L、0L、0L、0L、0L、0L、0L、, 1L,0L,0L,0L,0L,0L,0L,1L,0L,0L,0L,1L,0L,0L,0L,0L,0L,0L,0L,1L, 0L、1L、0L、0L、0L、0L、0L、1L、1L、1L、0L、0L、1L、0L、0L、0L、0L、0L、0L、, 1L,0L,0L,0L,0L,0L,1L,0L,1L,0L,0L,0L,0L,0L,0L,0L,1L,1L, 0L,0L,1L,0L,1L,0L,0L,1L,1L,0L,0L,0L,1L,1L,0L,0L,1L, 1L,1L,1L,0L,0L,1L,0L,0L,0L,1L,1L,1L,0L,0L,0L,0L,0L,0L,0L, 0L,0L,1L,1L,1L,0L,0L,0L,0L,0L,1L,1L,1L,1L,0L,0L, 0L,0L,1L,1L,0L,1L,0L,0L,0L,0L,0L,1L,0L,1L,1L,1L,0L, 1L,0L,1L,0L,0L,0L,1L,0L,1L,1L,0L,0L,0L,1L,1L,1L, 1L、1L、1L、1L、1L、0L、0L、0L、0L、1L、0L、0L、1L、1L、1L、1L、0L、, 1L,1L,1L,0L,0L,0L,0L,1L,0L,0L,0L,0L,0L,1L,1L,1L, 1L,1L,0L,0L,0L,1L,0L,0L,0L,0L,1L,1L,1L,1L,1L,1L,1L, 0L,0L,1L,0L,1L,0L,0L,0L,0L,0L,0L,1L,0L,0L,0L,0L,0L, 1L、0L、0L、1L、0L、0L、0L、1L、1L、0L、1L、1L、0L、1L、0L、1L、1L、1L、, 1L、1L、0L、0L、1L、0L、0L、0L、0L、0L、0L、1L、1L、0L、0L、0L、0L、1L、, 0L,0L,1L,0L,0L,0L,1L,0L,0L,0L,0L,0L,0L,1L,0L,0L,0L, 0L、1L、0L、1L、0L、0L、1L、0L、1L、1L、1L、1L、0L、0L、0L、0L、0L、0L、0L、, 1L、0L、0L、0L、0L、1L、0L、0L、0L、1L、0L、1L、1L、0L、0L、0L、0L、1L、, 0L,0L,0L,0L,0L,0L,1L,0L,0L,0L,0L,0L,0L,1L,1L,0L, 1L,1L,1L,0L,0L,0L,1L,0L,0L,0L,1L,0L,0L,0L,0L,0L,0L, 0L、0L、0L、0L、1L、1L、0L、1L、0L、0L、0L、0L、0L、0L、0L、0L、0L、0L、1L、, 0L,1L,0L,1L,0L,0L,0L,1L,0L,0L,1L,0L,1L,1L,0L,0L,0L, 1L,0L,0L,0L,1L,1L,0L,0L,0L,0L,0L,0L,0L,0L,0L,0L,1L,1L, 0L,1L,1L,0L,1L,0L,0L,0L,0L,0L,0L,0L,0L,0L,0L,0L,0L,0L,0L, 0L,0L,0L,1L,1L,0L,0L,0L,0L,0L,0L,0L,0L,0L,0L,0L,1L,0L, 0L、0L、0L、1L、0L、0L、1L、1L、0L、0L、0L、0L、1L、0L、0L、0L、0L、0L、1L、, 0L、0L、0L、0L、0L、0L、0L、0L、0L、0L、0L、1L、0L、0L、0L、1L、1L、, 0L,1L,1L,0L,0L,0L,1L,0L,1L,0L,0L,0L,0L,1L,1L,0L, 0L、0L、0L、0L、1L、0L、0L、0L、0L、1L、1L、1L、0L、1L、1L、0L、1L、1L、0L、, 0L、1L、0L、1L、0L、0L、1L、1L、0L、1L、0L、1L、0L、1L、0L、1L、1L、0L、1L、0L、, 1L、1L、0L、0L、0L、0L、1L、1L、1L、0L、0L、1L、0L、0L、1L、0L、1L、0L、1L、0L、, 0L,0L,0L,0L,1L,1L,0L,1L,1L,0L,0L,0L,1L,1L,1L,0L,0L,0L, 0L,0L,0L,1L,0L,0L,0L,0L,0L,0L,0L,0L,0L,0L,0L,0L,1L,0L, 0L、0L、0L、0L、0L、0L、1L、1L、1L、1L、1L、0L、0L、0L、0L、0L、0L、0L、0L、, 0L,0L,0L,0L,0L,0L,1L,0L,0L,0L,0L,0L,1L,0L,0L,0L,0L,0L,0L, 1L,0L,0L,0L,0L,0L,0L,0L,0L,1L,0L,0L,0L,1L,0L,0L,0L,0L,0L,1L, 1L、0L、0L、0L、1L、1L、0L、1L、1L、1L、0L、1L、1L、1L、1L、1L、1L、, 奖学金是否=c(0L,0L,0L,0L,0L,0L,0L,0L,0L,0L,0L, 1L,0L,1L,0L,1L,1L,0L,1L,0L,0L,1L,1L,0L,0L,0L,0L,0L, 1L,1L,0L,1L,0L,0L,0L,1L,0L,0L,0L,0L,0L,0L,0L,0L,0L, 0L、0L、0L、0L、0L、0L、0L、0L、0L、0L、0L、0L、0L、1L、0L、1L、, 0L,0L,0L,0L,0L,0L,0L,0L,0L,0L,1L,0L,0L,0L,0L,0L,0L,1L, 0L,0L,0L,0L,0L,0L,0L,0L,0L,0L,0L,0L,0L,0L,0L,0L,0L,0L, 1L,0L,1L,1L,1L,0L,0L,1L,0L,0L,0L,0L,0L,0L,0L,0L, 0L,0L,0L,1L,1L,0L,0L,0L,0L,1L,0L,0L,0L,0L,0L,0L,0L, 0L,0L,1L,0L,0L,1L,1L,0L,0L,0L,0L,1L,1L,1L,1L,0L, 0L,0L,0L,0L,0L,1L,0L,1L,0L,0L,0L,0L,0L,1L,0L,0L,0L,0L,0L, 0L,0L,0L,0L,1L,1L,0L,0L,0L,0L,0L,0L,0L,0L,0L,0L,0L, 0L,0L,1L,1L,0L,0L,0L,0L,0L,1L,0L,1L,0L,0L,0L,1L, 0L,0L,0L,1L,1L,0L,0L,1L,0L,0L,1L,1L,0L,0L,0L,0L,1L, 0L,1L,0L,1L,0L,1L,1L,0L,0L,0L,0L,1L,0L,0L,0L,0L,0L, 0L、0L、0L、0L、1L、1L、0L、0L、0L、0L、0L、0L、0L、1L、0L、0L、0L、, 0L,0L,0L,1L,0L,0L,0L,0L,0L,0L,0L,0L,0L,0L,0L,0L,0L,1L, 0L、0L、0L、0L、0L、1L、1L、0L、0L、0L、0L、0L、1L、0L、0L、0L、, 0L,0L,0L,0L,0L,1L,0L,0L,0L,0L,0L,0L,0L,1L,0L,0L,0L, 0L、0L、0L、1L、0L、1L、0L、1L、1L、0L、0L、0L、1L、1L、1L、0L、, 0L,0L,1L,0L,0L,0L,0L,0L,0L,0L,0L,1L,0L,0L,0L,0L,1L, 1L,0L,0L,0L,0L,0L,0L,0L,0L,0L,0L,0L,0L,0L,1L,1L, 1L,1L,0L,1L,0L,0L,0L,1L,0L,1L,0L,0L,1L,0L,0L,0L,0L, 0L,0L,0L,0L,0L,0L,0L,0L,0L,0L,0L,1L,0L,1L,1L,0L, 1L,1L,0L,0L,0L,0L,0L,0L,0L,0L,0L,1L,0L,0L,0L,0L,0L, 1L,0L,1L,0L,0L,0L,0L,1L,0L,0L,1L,0L,0L,0L,1L,0L, 0L,0L,1L,1L,0L,0L,1L,0L,0L,0L,0L,0L,0L,0L,0L,0L,0L, 0L、0L、0L、0L、0L、0L、1L、0L、0L、1L、0L、0L、0L、0L、0L、0L、0L、0L、, 0L,0L,0L,0L,0L,0L,0L,0L,0L,0L,0L,0L,0L,0L,0L,0L,0L,1L, 1L,0L,1L,1L,0L,0L,1L,0L,0L,1L,0L,1L,0L,0L,0L,0L, 0L、0L、1L、1L、0L、0L、0L、1L、1L、0L、1L、1L、0L、0L、0L、1L、, 0L、0L、0L、0L、0L、1L、0L、0L、1L、0L、1L、0L、1L、0L、0L、0L、0L、, 1L,0L,0L,0L,0L,0L,0L,1L,0L,0L,0L,0L,0L,0L,0L,0L,0L,0L, 0L,0L,0L,1L,0L,0L,1L,0L,0L,0L,0L,0L,0L,0L,0L,0L,0L, 0L、0L、0L、0L、0L、1L、0L、1L、0L、0L、0L、0L、0L、1L、0L、1L、, 0L,0L,0L,0L,0L,0L,0L,1L,0L,0L,0L,0L,0L,0L,0L,0L,0L,0L,0L, 0L、0L、1L、0L、0L、1L、0L、0L、1L、0L、0L、0L、0L、0L、0L、0L、, 0L,0L,0L,1L,0L,1L,0L,0L,0L,1L,1L,1L,1L,0L,1L, 1L,1L,0L,0L,1L,0L,0L,0L,0L,0L,0L,1L,0L,0L,0L,0L,0L, 0升,1升,0升,0升,0升,0
getwd()
cba = read.table("cba_admissions_1999.txt", sep = "\t", header = T, quote = "", allowEscapes = T)
#PART A
scholars <- sum(cba$scholarship_yes_no == 1)
scholars

scholar_percent = scholars/880 * 100
scholar_percent
#number of students who were offered scholarships is 205 and the percentage is abou 23.3%

#PART B
females <- sum(cba$Female == 1)
females
female_scholars <- sum(cba$scholarship_yes_no == 1 & cba$Female == 1)
female_scholars
fem_scholar_percent = female_scholars / scholars *100
fem_scholar_percent

other_females <- sum(cba$scholarship_yes_no == 0 & cba$Female == 1)
other_females
fem_percent = other_females / (880 - scholars) * 100
fem_percent

#Of the students on scholarship, about 50% are women. Of the students who are not on scholarship, about 43.5% are women.
#PART C
female_scholar_summary <- cba[cba$scholarship_yes_no == 1 & cba$Female == 1,]
mean(female_scholar_summary$Max_Test_Score)
sd(female_scholar_summary$Max_Test_Score)

female_summary <- cba[cba$scholarship_yes_no == 0 & cba$Female == 1,]
mean(female_summary$Max_Test_Score)
sd(female_summary$Max_Test_Score)

#The mean test score for females on scholarship is 1255.437 with SD of 105.3358 and the mean for females not on scholarship is 1095.17 with SD of 82.39
#PART D
scholarships = split(cba,cba$scholarship_yes_no)
not_scholar = scholarships[["0"]]
scholar = scholarships[["1"]]
scholarships_yes_females = split(scholar, scholar$Female)
scholarships_no_females= split(not_scholar, not_scholar$Female)
scholarships_female = scholarships_yes_females[["1"]]
test_female_scholar = scholarships_female$Max_Test_Score
no_scholarships_females = scholarships_no_females[["1"]]
test_female_not_scholar = scholarships_female$Max_Test_Score

par(mfrow = c(1,2))
hist(test_female_scholar, xlab = "Max Test Score", main = "Female Students on Scholarship", ylab = "Numnber of Students" )
hist(test_female_not_scholar, xlab = "Max Test Score", main = "Female Students not on Scholarship", ylab = "Number of Students")
#PART E
women = cba[cba$Female==1,]
boxplot(women$Max_Test_Score ~ women$scholarship_yes_no)
#PART F
scholar_female_dist = scholarships_female$distancefromPitt
summary(scholar_female_dist)
not_scholar_female_dist = no_scholarships_females$distancefromPitt
summary(not_scholar_female_dist)
#The closer a female student lives to Pitt, the less likely she is to get a scholarship
#PART G
paid_deposit_scholar = split(paid_deposit_yes, paid_deposit_yes$scholarship_yes_no)
paid_deposit_scholar = paid_deposit_scholar[["1"]]
paid_deposit_not_scholar = paid_deposit_scholar[["0"]]
paid_deposit = split(cba, cba$paiddeposit)
paid_deposit_yes = paid_deposit[["1"]]
paid_deposit_no = paid_deposit[["0"]]
female_paid_scholar = (paid_deposit_yes$scholarships_female)
length(female_paid_scholar)/length(scholarships_female)