R Coding Challenges
Practice R step by step. Code, run tests, and ask the AI Tutor for hints.
Square a Number
Write an R function solution(x) that returns the square of its input. Example solution(4) → 16 s...
Mean of a Vector
Write an R function solution(x) that returns the arithmetic mean of the numeric vector x. Example ...
Sum of a Vector
Write an R function solution(x) that returns the sum of all elements in the numeric vector x. Examp...
Maximum of a Vector
Write an R function solution(x) that returns the maximum value in the numeric vector x. Example so...
Minimum of a Vector
Write an R function solution(x) that returns the minimum value in the numeric vector x. Example so...
Length of a Vector
Write an R function solution(x) that returns the number of elements in the vector x. Example solut...
Reverse a Vector
Write an R function solution(x) that returns the vector x in reverse order. Example solution(c(1, ...
Sort Vector Ascending
Write an R function solution(x) that returns the elements of x sorted in ascending order. Example ...
Unique Elements
Write an R function solution(x) that returns the unique elements of x, keeping their first-appearanc...
Factorial
Write an R function solution(x) that returns the factorial of the non-negative integer x. Example ...
Check Even Numbers
Write an R function solution(x) that returns a logical vector indicating which elements of x are eve...
Sample Variance
Write an R function solution(x) that returns the sample variance of the numeric vector x. Example ...
Median
Write an R function solution(x) that returns the median of the numeric vector x. Example solution(...
Cumulative Sum
Write an R function solution(x) that returns the cumulative sum of the numeric vector x. Example s...
Concatenate Strings
Write an R function solution(x) that concatenates the character vector x into a single string with n...
Uppercase Strings
Write an R function solution(x) that returns the character vector x converted to uppercase. Example...
Absolute Value
Write an R function solution(x) that returns the absolute value of each element in the numeric vecto...
Count Positive Values
Write an R function solution(x) that returns how many elements of the numeric vector x are strictly ...
Product of a Vector
Write an R function solution(x) that returns the product of all elements in the numeric vector x. E...
Count Distinct Groups
Write an R function solution(x) that uses dplyr to return the number of distinct values in the colum...
Range (Max Minus Min)
Write an R function solution(x) that returns the range (maximum minus minimum) of the numeric vector...
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...
Maximum Group Total
Write an R function solution(x) that uses dplyr to group x by group, sum the value column within eac...