How to run and interpret a one-sample t-test in R with t.test() — testing whether a sample mean differs from a known value, plus the assumptions to check.
Author
Rverse Analytics
Published
May 31, 2026
The one-sample t-test answers a focused question: is my group’s mean different from a specific reference value? — a target, a historical norm, a label claim. Here’s how to run and read it in R. (Just want the result from your data? Use our t-test calculator.)
The setup
Say a bag of chips is labelled 50 g. You weigh 20 bags and want to know whether the true mean weight differs from 50.
set.seed(9)weights <-rnorm(20, mean =49.2, sd =2) # sample datat.test(weights, mu =50)
One Sample t-test
data: weights
t = -2.5275, df = 19, p-value = 0.02051
alternative hypothesis: true mean is not equal to 50
95 percent confidence interval:
47.97349 49.80942
sample estimates:
mean of x
48.89146
Reading the output
t and df: the test statistic and degrees of freedom (n − 1).
p-value: how surprising this sample mean is if the true mean were 50. Small p → evidence it isn’t 50.
95% confidence interval: the plausible range for the true mean. If it excludes 50, the difference is significant at α = .05 — the CI and the p-value always agree.
sample estimate: the observed mean.
One-sided version
If you only care about underfilling (mean less than 50), use a one-sided test — but decide that before seeing the data:
t.test(weights, mu =50, alternative ="less")$p.value
[1] 0.01025591
Check the assumption
The one-sample t-test assumes the values are roughly normal (it’s robust for larger n thanks to the central limit theorem). For a small sample, check with a Q–Q plot — see checking normality in R. If normality clearly fails, use the Wilcoxon signed-rank test (wilcox.test(weights, mu = 50)).
And report an effect size alongside the p-value, so readers know how far from 50 you are, not just that it’s “significant.”
Need this on your own data with assumptions checked and written up? That’s our work.