Bird
Raised Fist0
R Programmingprogramming~20 mins

Descriptive statistics in R Programming - Practice Problems & Coding Challenges

Choose your learning style10 modes available
Challenge - 5 Problems
🎖️
Descriptive Statistics Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ Predict Output
intermediate
2:00remaining
Calculate the mean and median of a numeric vector
What is the output of this R code that calculates the mean and median of the vector c(2, 4, 6, 8, 10)?
R Programming
x <- c(2, 4, 6, 8, 10)
mean_x <- mean(x)
median_x <- median(x)
c(mean_x, median_x)
A[1] 5 5
B[1] 6 5
C[1] 5 6
D[1] 6 6
Attempts:
2 left
💡 Hint
Recall that mean is the average and median is the middle value when sorted.
❓ data_output
intermediate
2:00remaining
Count the number of unique values in a factor
Given the factor f <- factor(c('apple', 'banana', 'apple', 'orange', 'banana', 'banana')), what is the output of length(levels(f))?
R Programming
f <- factor(c('apple', 'banana', 'apple', 'orange', 'banana', 'banana'))
length(levels(f))
A1
B2
C3
D6
Attempts:
2 left
💡 Hint
Levels represent unique categories in a factor.
❓ visualization
advanced
2:30remaining
Interpret a boxplot of numeric data
What does the boxplot of the numeric vector c(1, 2, 2, 3, 4, 5, 6, 7, 8, 20) show about the data distribution?
R Programming
x <- c(1, 2, 2, 3, 4, 5, 6, 7, 8, 20)
boxplot(x, main = 'Boxplot of x')
AThe boxplot shows a left-skewed distribution with an outlier at 1.
BThe boxplot shows a right-skewed distribution with an outlier at 20.
CThe boxplot shows a symmetric distribution with no outliers.
DThe boxplot shows uniform distribution with no outliers.
Attempts:
2 left
💡 Hint
Look for the position of the median and any points outside whiskers.
🧠 Conceptual
advanced
1:30remaining
Understanding variance and standard deviation
Which statement correctly describes the relationship between variance and standard deviation?
AStandard deviation is the square root of variance, both measure data spread.
BVariance is the square root of standard deviation, both measure central tendency.
CVariance and standard deviation are unrelated statistics.
DStandard deviation is always larger than variance.
Attempts:
2 left
💡 Hint
Think about how variance and standard deviation relate mathematically.
🔧 Debug
expert
2:00remaining
Identify the error in calculating the mode
What error does this R code produce when trying to calculate the mode of vector v <- c(1, 2, 2, 3, 4) using mode_v <- mode(v)?
R Programming
v <- c(1, 2, 2, 3, 4)
mode_v <- mode(v)
mode_v
AIt returns the storage mode of the vector, not the statistical mode.
BIt raises a syntax error because mode() is not a valid function.
CIt returns the most frequent value correctly.
DIt returns NULL because the vector is numeric.
Attempts:
2 left
💡 Hint
Check what the mode() function returns in R base.

Practice

(1/5)
1. Which of the following best describes the mean in descriptive statistics?
easy
A. The average value of a numeric dataset
B. The middle value when data is sorted
C. The most frequent value in the dataset
D. The difference between the largest and smallest values

Solution

  1. Step 1: Understand the definition of mean

    The mean is calculated by adding all numbers and dividing by the count.
  2. Step 2: Compare with other options

    Median is the middle value, mode is most frequent, range is difference between max and min.
  3. Final Answer:

    The average value of a numeric dataset -> Option A
  4. Quick Check:

    Mean = Average [OK]
Hint: Mean is sum divided by count, simple average [OK]
Common Mistakes:
  • Confusing mean with median
  • Thinking mean is the most frequent value
  • Mixing mean with range
2. Which R function gives a quick summary including min, 1st Qu., median, mean, 3rd Qu., and max for numeric data?
easy
A. mean()
B. var()
C. sd()
D. summary()

Solution

  1. Step 1: Recall function purposes

    mean() calculates average, var() variance, sd() standard deviation.
  2. Step 2: Identify summary function

    summary() provides min, quartiles, median, mean, and max in one output.
  3. Final Answer:

    summary() -> Option D
  4. Quick Check:

    summary() = quick overview [OK]
Hint: summary() shows min, quartiles, median, mean, max [OK]
Common Mistakes:
  • Using mean() expecting full summary
  • Confusing sd() with summary()
  • Trying var() for descriptive summary
3. What is the output of this R code?
data <- c(4, 8, 6, 5, 3, 7)
mean(data)
medium
A. 5.5
B. 6
C. 4.5
D. 5

Solution

  1. Step 1: Sum the data values

    4 + 8 + 6 + 5 + 3 + 7 = 33
  2. Step 2: Divide sum by number of values

    There are 6 values, so 33 / 6 = 5.5
  3. Final Answer:

    5.5 -> Option A
  4. Quick Check:

    Mean = 33/6 = 5.5 [OK]
Hint: Add all numbers, divide by count [OK]
Common Mistakes:
  • Adding incorrectly
  • Dividing by wrong count
  • Confusing mean with median
4. Identify the error in this R code for calculating variance:
data <- c(2, 4, 6, 8)
var_data <- var(data, na.rm=TRUE)
print(var_data)
medium
A. Missing parentheses in var() function
B. No error, code runs correctly
C. na.rm argument is invalid for var()
D. Variable data is not defined

Solution

  1. Step 1: Check variable definition

    data is defined as a numeric vector correctly.
  2. Step 2: Verify var() usage

    var() accepts na.rm=TRUE to remove missing values; syntax is correct.
  3. Final Answer:

    No error, code runs correctly -> Option B
  4. Quick Check:

    var() with na.rm=TRUE is valid [OK]
Hint: var() accepts na.rm=TRUE to ignore NAs [OK]
Common Mistakes:
  • Thinking na.rm is invalid for var()
  • Assuming missing parentheses error
  • Not defining data before use
5. You have a numeric vector v <- c(10, 20, 30, NA, 40, 50). Which R code correctly calculates the mean ignoring the missing value?
hard
A. mean(na.exclude(v))
B. mean(v, na.rm=TRUE)
C. Both B and C
D. mean(v)

Solution

  1. Step 1: Understand missing value handling

    By default, mean() returns NA if vector has NA values.
  2. Step 2: Check options to ignore NA

    mean(v, na.rm=TRUE) removes NA before calculation. mean(na.exclude(v)) also removes NA values before calculation, so it returns the mean ignoring NA as well. mean(v) returns NA.
  3. Final Answer:

    Both mean(v, na.rm=TRUE) and mean(na.exclude(v)) -> Option C
  4. Quick Check:

    na.rm=TRUE and na.exclude() both remove NA for mean calculation [OK]
Hint: Use na.rm=TRUE or na.exclude() to ignore NA [OK]
Common Mistakes:
  • Using mean() without na.rm=TRUE returns NA
  • Not removing NA before mean calculation
  • Confusing na.rm with na.exclude
Recommended

Ready to prove it?

Pass the test and this pattern moves unknown strong while earning +1 Grip toward your certificate.

10 questions~5 mineasy hard