[R] compare the sum, and report with if{}else if{}

You may need to compare the frequency of inquiries about grade distribution and teaching style in the GE_survey dataset. Assuming you have variables in your dataset that represent these inquiries (let's call them Q_grade_distribution and Q_teaching_style for this example), you can use the sum() function to count the number of "Yes" responses for each inquiry and then compare them. Here's how you might do it:

R 复制代码
# Count the number of inquiries about grade distribution
inquiries_grade_distribution <- sum(GE_survey$Q_grade_distribution == "Yes", na.rm = TRUE)

# Count the number of inquiries about teaching style
inquiries_teaching_style <- sum(GE_survey$Q_teaching_style == "Yes", na.rm = TRUE)

# Compare the inquiries
if (inquiries_grade_distribution > inquiries_teaching_style) {
    print("Students are more likely to inquire about grade distribution.")
} else if (inquiries_grade_distribution < inquiries_teaching_style) {
    print("Students are more likely to inquire about teaching style.")
} else {
    print("Students are equally likely to inquire about grade distribution and teaching style.")
}

In this code, Q_grade_distribution and Q_teaching_style should be replaced with the actual variable names in your GE_survey dataset that represent the inquiries about grade distribution and teaching style, respectively. The sum() function counts the number of "Yes" responses for each inquiry, and the if statement compares the counts to determine which inquiry is more common.

相关推荐
popcorn_min3 小时前
共享单车需求预测:时间特征工程 + 随机森林,R² 达到 0.931
随机森林·r语言·kotlin
m0_497048934 天前
.NET10+Avalonia跨平台截屏工具解析
r语言
dongf20195 天前
R语言朴素贝叶斯算法---iris数据集
开发语言·算法·数据分析·r语言
All_Will_Be_Fine噻5 天前
重建R环境
开发语言·r语言
梦想的初衷~5 天前
基于R语言APSIM模型高级应用及批量模拟
r语言·apsim·作物生长模型·农业模拟·气象数据处理·土壤水分平衡
dongf20195 天前
R 语言 逻辑斯蒂回归
开发语言·数据分析·回归·r语言
dongf20198 天前
R 语言 Apriori 关联规则算法
数据分析·r语言·关联规则
dongf20198 天前
R语言决策树剪枝----泰坦尼克数据集
决策树·r语言·剪枝
dongf20198 天前
R语言分类决策数算法----iris数据集
分类·数据分析·r语言
dongf20198 天前
R语言决策树----mtcars数据集
决策树·r语言