R Coding Challenges

Practice R step by step. Code, run tests, and ask the AI Tutor for hints.

23 Challenges Available
All Challenges R Basics Vectors Strings Statistics Conditional Statements dplyr
easy

Square a Number

Write an R function solution(x) that returns the square of its input. Example solution(4) → 16 s...

R Basics Solve →
easy

Mean of a Vector

Write an R function solution(x) that returns the arithmetic mean of the numeric vector x. Example ...

statistics Solve →
easy

Sum of a Vector

Write an R function solution(x) that returns the sum of all elements in the numeric vector x. Examp...

R Basics Solve →
easy

Maximum of a Vector

Write an R function solution(x) that returns the maximum value in the numeric vector x. Example so...

R Basics Solve →
easy

Minimum of a Vector

Write an R function solution(x) that returns the minimum value in the numeric vector x. Example so...

R Basics Solve →
easy

Length of a Vector

Write an R function solution(x) that returns the number of elements in the vector x. Example solut...

R Basics Solve →
easy

Reverse a Vector

Write an R function solution(x) that returns the vector x in reverse order. Example solution(c(1, ...

vectors Solve →
easy

Sort Vector Ascending

Write an R function solution(x) that returns the elements of x sorted in ascending order. Example ...

vectors Solve →
easy

Unique Elements

Write an R function solution(x) that returns the unique elements of x, keeping their first-appearanc...

vectors Solve →
easy

Factorial

Write an R function solution(x) that returns the factorial of the non-negative integer x. Example ...

R Basics Solve →
easy

Check Even Numbers

Write an R function solution(x) that returns a logical vector indicating which elements of x are eve...

Conditional Statements Solve →
easy

Sample Variance

Write an R function solution(x) that returns the sample variance of the numeric vector x. Example ...

statistics Solve →
easy

Median

Write an R function solution(x) that returns the median of the numeric vector x. Example solution(...

statistics Solve →
easy

Cumulative Sum

Write an R function solution(x) that returns the cumulative sum of the numeric vector x. Example s...

vectors Solve →
easy

Concatenate Strings

Write an R function solution(x) that concatenates the character vector x into a single string with n...

Strings Solve →
easy

Uppercase Strings

Write an R function solution(x) that returns the character vector x converted to uppercase. Example...

Strings Solve →
easy

Absolute Value

Write an R function solution(x) that returns the absolute value of each element in the numeric vecto...

R Basics Solve →
easy

Count Positive Values

Write an R function solution(x) that returns how many elements of the numeric vector x are strictly ...

Conditional Statements Solve →
easy

Product of a Vector

Write an R function solution(x) that returns the product of all elements in the numeric vector x. E...

R Basics Solve →
easy

Count Distinct Groups

Write an R function solution(x) that uses dplyr to return the number of distinct values in the colum...

dplyr Solve →
medium

Range (Max Minus Min)

Write an R function solution(x) that returns the range (maximum minus minimum) of the numeric vector...

vectors Solve →
medium

Mean of a Column

Write an R function solution(x) that uses dplyr to return the mean of the column value in the data f...

dplyr Solve →
hard

Maximum Group Total

Write an R function solution(x) that uses dplyr to group x by group, sum the value column within eac...

dplyr Solve →