1/49
Looks like no tags are added yet.
Name | Mastery | Learn | Test | Matching | Spaced |
---|
No study sessions yet.
Q: How do you filter rows from students where GPA is above 3.5 using subset()?
A: subset(students, GPA > 3.5)
Q: How do you count how many students have a score over 79 using nrow()?
A: nrow(subset(students, score > 79))
Q: How do you create a frequency table for students’ seniority?
A: table(students$seniority)
Q: How do you filter students with GPA > 3.5 and seniority is "Freshman"?
A: subset(students, GPA > 3.5 & seniority == "Freshman")
Q: How do you calculate average GPA for each Seniority level?
A: tapply(students$GPA, students$seniority, mean)
Q: How do you count how many students are in each major?
A: tapply(students$major, students$major, length)
Q: How do you draw a boxplot comparing GPA by gender?
A: boxplot(GPA ~ gender, data = students)
Q: How do you draw a barplot of the number of students per major?
A: barplot(table(students$major))
Q: How do you make a scatter plot of score vs GPA?
A: plot(students$score, students$GPA)
Q: How do you fix this line if it's invalid: boxplot(score ~ seniority + major, data = moody)?
A: Convert one combined factor: boxplot(score ~ interaction(seniority, major), data = moody)
Q: How do you create a new column decision initialized to "No"?
A: decision <- rep("No", nrow(students))
Q: How do you update decision to "Yes" for CS majors with GPA > 3.5?
A: decision[students$major == "CS" & students$GPA > 3.5] <- "Yes"
Q: How do you classify students as "Pass" if score > 50, else "Fail"?
A: decision <- ifelse(students$score > 50, "Pass", "Fail")
Q: How do you assign scholarship levels: "Full" for GPA > 3.8, "Basic" for GPA > 3.0, else "None"?
decision <- rep("None", nrow(students))
decision[students$GPA > 3.0] <- "Basic"
decision[students$GPA > 3.8] <- "Full"
Q: How do you assign "Likely Graduate" if GPA > 3.2 OR Credits > 100?
A: decision[students$GPA > 3.2 | students$Credits > 100] <- "Likely Graduate"
Q: How do you build a 2-way frequency table for gender and department?
A: table(students$gender, students$department)
Q: How do you test for independence using chisq.test()?
A: chisq.test(table(students$gender, students$department))
Q: What happens with chisq.test(students$GPA, students$major)? Why?
A: It gives an error because both variables must be categorical. GPA is numeric.
Q: What is a false positive in Bayesian reasoning?
A: When the test says positive but the condition is actually false.
Q: How do you read and save the Moody dataset from a URL?
Q: What's the error here: tapply(data$score, data$grade)?
A: Missing third argument (function)
Q: What's the error here: subset(df, score > 80, grade)?
A: No error
Q: What's the error here: table(df$Gender, df$Income)?
A: No error
Q: Error in boxplot(height ~ gender + age, data = people)?
A: Nothing is wrong
Q: Will barplot(table(data$color)) fail?
A: No, it's valid
Q: What's the issue with nrow(data == "USA")?
A: nrow() requires a data frame
Q: Problem with plot(df$income, df$gender)?
A: Gender is not numeric
Q: Why does subset(df, age > 30 & salary) fail?
A: Salary must be logical
Q: Error in chisq.test(df$income, df$age)?
A: Variables must be categorical
Q: What's wrong with tapply(df$score, mean, df$group)?
A: Wrong order of arguments
Q: Best way to count rows where age > 30?
A: nrow(subset(people, age > 30))
Q: What does tapply(df$score, df$group, mean) compute?
A: Mean of score per group
Q: Best plot to compare score distribution by major?
Boxplot
Q: What does a barplot usually show?
A: Frequency of categories
Q: What's a false positive in Bayesian terms?
A: Test is positive but condition is false
Q: What is a true positive?
A: Test detects the condition correctly
Q: Purpose of chisq.test(table(df$Gender, df$Outcome))?
A: Test independence between gender and outcome
Q: Which function counts how many times each value appears in a column?
A: table()
Q: Best plot to show relationship between height and weight?
A: Scatter plot
Q: How to count number of females in dataset?
A: nrow(subset(students, gender == "F"))
Q: How to initialize prediction to "No" for all rows?
A: decision <- rep("No", nrow(df))
Q: Update decision to "Yes" for CS majors with GPA > 3.5?
A: decision[Major == "CS" & GPA > 3.5] <- "Yes"
Q: Classify students as "Pass" if score > 50, else "Fail"?
A: decision <- ifelse(df$Score > 50, "Pass", "Fail")
Q: Set "Excellent" for students with Attendance > 90%?
A: decision[df$Attendance > 90] <- "Excellent"
Q: Rule: GPA > 3.2 and Score > 80 → "Offer". Logic?
A: decision[GPA > 3.2 & Score > 80] <- "Offer"
Q: Scholarship logic with GPA > 3.0 = Basic, GPA > 3.8 = Full. What’s the result?
A: Students with GPA > 3.8 get "Full" (correct, order matters)
Q: Income category logic: Low, Medium, High. What’s the correct order to assign?
A: Set "Low", then "Medium", then "High" (to avoid overwriting)
Q: Logic for "Likely Graduate" if GPA > 3.2 OR Credits > 100?
A: decision[GPA > 3.2 | Credits > 100] <- "Likely Graduate"
Q: Logic to assign "Eligible" if Score > 85 AND GPA > 3.7?
A: decision[df$Score > 85 & df$GPA > 3.7] <- "Eligible"
Q: If GPA = 3.9, Score = 60, and code assigns "Maybe" for GPA > 3.5, "Yes" for Score > 80 — what’s the result?
A: "Maybe"