Back to Practice
#0177

Mean by Group With aggregate in R

EasyR15 min10 XP

Problem

Given a data frame with team and score, return mean score per team.

Why This Matters

Before tidyverse, base R aggregate is the simplest way to summarize data by group.

Examples

Example 1
InputA scores 10 and 20; B score 30
OutputA mean 15, B mean 30

aggregate applies mean separately inside each team.

Constraints

  • Return the exact requested output.
  • Handle ordinary edge cases.
  • Prefer simple, interview-readable code.
CodeR
Visible browser tests run here when available.
Testcases1 visible / 3 hidden categories
Core example
InputA scores 10 and 20; B score 30
ExpectedA mean 15, B mean 30

aggregate applies mean separately inside each team.

Hidden Test Categories
empty or minimal inputduplicates or tieslarger input