我在一个问题的一部分中偶然发现了。
id <-1:6
age <- c(18,20,19,23,26,24)
gender <- c("M","M","F","F","M","F")
gpa <- c(3.2,2.5,2.7,3.7,4.1,3.6)
score <- c(570,530,550,650,690,640)
data <- data.frame(id=id,gender=gender,gpa=gpa,ceescore=score)
data$class <- with(data,ifelse(gpa>3.5,"First Class",
ifelse(gpa>=2.5 & gpa<=3.5,"Second class",
ifelse(gpa<2.5,"Third class",NA))))
data$final_score <- with(data,ifelse(gpa>3,ceescore*gpa,ceescore*gpa*0.8))
data$success <- with(data,ifelse(final_score>2000,1,0))
现在我必须计算成功的女性(女性为F)(成功== 1)
我无法管理它。
提前感谢。
答案 0 :(得分:1)
with(data, sum(gender == "F" & success))
会做到这一点。