Basic Statistics in R

Interactive R tutorial: compute means, standard deviations and summaries, make a frequency table, run a t-test and a correlation β€” live in your browser.

Now the fun part β€” actual statistics, run live. Edit and Run each box.

Watch: statistics in two minutes

See summaries, a frequency table, a correlation, a t-test and a linear model run live in RStudio β€” then run each one yourself in the consoles below.

Download the R script  Β·  β–Ά Practice in the playground β€” or edit and run each snippet below.

Summary statistics

summary() gives the minimum, quartiles, median, mean and maximum in one call.

Frequency table

Count how many cars have each cylinder count:

Correlation

How strongly are two variables related? (βˆ’1 to +1)

A strong negative value: heavier cars have clearly lower mpg. (Pearson vs Spearman.)

Your first t-test

Do automatic and manual cars differ in fuel efficiency? A t-test answers it:

Look at the p-value: small (below 0.05) means the difference is unlikely to be chance. (What a p-value really means.)

Fit a simple model

That summary() is a full linear regression β€” coefficients, p-values and RΒ². (How to read it.)

Your turn


You’ve run summaries, a t-test, a correlation and a regression β€” the core of applied statistics.

Next: Data wrangling with dplyr β†’ β€” the modern way to reshape and summarise data.