Back to Practice
#0089

Standardize an R Vector

EasyR12 min10 XP

Problem

Given x <- c(10, 20, 30), write R code that returns z-scores using (x - mean(x)) / sd(x).

Why This Matters

Vectorized thinking is central to R. Standardization is also a key preprocessing step in statistics and ML.

Examples

Example 1
Inputc(10, 20, 30)
Outputapproximately c(-1, 0, 1)

The middle value equals the mean.

Constraints

  • Use vectorized arithmetic.
  • Use mean and sd.
  • Do not loop manually.
CodeR
Visible browser tests run here when available.
Testcases1 visible / 3 hidden categories
Three values
Inputc(10,20,30)
Expectedc(-1,0,1) approximately

R applies arithmetic element-wise.

Hidden Test Categories
negative valuesdecimal valuesconstant vector discussion