Practice Real Company Assessment Patterns • Latest 2025–2026 Mock Tests

Programming Exercises

Create a function that accepts a data frame and a column name and calculates the mean of that column.

Medium

Problem Statement

Create a function that accepts a data frame and a column name and calculates the mean of that column.

Sample Input

Data Frame: 
 Name Age
1 John 25
2 Alice 30
3 Bob 22
Column: Age

Sample Output

Mean of Age: 25.67

Limits

Time: 2s · Memory: 256 MB

Code Editor
00:00
# Predefined structure calculate_column_mean <- function(df, column_name) { # Your logic here } mean_age <- calculate_column_mean(data, "Age") print(paste("Mean of Age:", round(mean_age, 2)))
Log in or sign up to run or submit your code.Log inSign up
Input
Data Frame: 
 Name Age
1 John 25
2 Alice 30
3 Bob 22
Column: Age
Expected Output
Mean of Age: 25.67