You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何查找成绩排名第三的学生(含并列排名场景)

R语言获取并列排名下所有第三名学生方案

实现思路

  • 对所有成绩去重后按从高到低排序,直接取排序后第3位的成绩作为第三名的分数阈值
  • 筛选所有成绩等于该阈值的学生,天然支持多人并列第三名的场景

完整代码示例

# 输入数据
names <- c('Alex', 'Joy', 'Cindy', 'Lily')
score <- c(80, 80, 100, 90)

# 处理逻辑
sorted_unique_scores <- sort(unique(score), decreasing = TRUE)
# 排名合法性校验,避免成绩不足三个档位时报错
if (length(sorted_unique_scores) < 3) {
  cat("当前成绩数据不存在第三名")
} else {
  third_place_score <- sorted_unique_scores[3]
  third_students <- names[score == third_place_score]
  # 格式化输出结果
  cat(paste0("第三名的学生:", paste(third_students, collapse = "、")))
}

运行结果

运行上述示例代码将输出:
第三名的学生:Alex、Joy

内容的提问来源于stack exchange,提问作者nisa

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.10.03 13:39:04