R is a free programming language built for statistics. It is what many statisticians, epidemiologists, and psychologists actually use to analyse study data, and it is one of the two engines KyroStat runs behind the scenes. Learning even a little R pays off twice: you understand what your statistics software is really doing, and you can read the analysis code that journals and supervisors increasingly ask for.
This course uses only base R: no packages to install, no setup. Every grey code panel has a "Run it yourself" link that opens our in-browser playground with the code preloaded. Change the numbers, break things, rerun. That is how it sticks.
R is a calculator that remembers
At its core, R evaluates expressions and stores results in named objects with the <- arrow. A collection of values is a vector, made with c() (for combine), and most R functions happily take a whole vector at once.
# Scores from a small pilot study
scores <- c(72, 85, 91, 68, 77, 88, 95, 60)
mean(scores) # average
sd(scores) # standard deviation
length(scores) # how many valuesOutput
[1] 79.5
[1] 12.24745
[1] 8Everything after a # is a comment. The [1] in the output is just R labelling the position of the first printed value.
Data lives in data frames
A data frame is R's spreadsheet: rows are observations (participants, trials, samples), columns are variables. R ships with practice datasets, and this course leans on them so every example is reproducible anywhere. mtcars records 11 measurements for 32 cars; head() shows the first rows and str() summarises the structure.
head(mtcars) # first 6 rows
str(mtcars) # structure: 32 obs. of 11 variablesYou reach into a data frame with the $ sign: mtcars$mpg is the fuel-efficiency column as a plain vector, ready for any function.
mean(mtcars$mpg)
range(mtcars$mpg)Output
[1] 20.09062
[1] 10.4 33.9Your own data would load the same way
With R installed on your computer, one line reads a CSV exported from Excel, Qualtrics, or a lab instrument into a data frame. (It needs a file on disk, so it will not run in the browser playground, everything else in this course will.)
mydata <- read.csv("study_data.csv")
head(mydata)What you can do already
- Store values in named objects with
<- - Build vectors with
c()and summarise them withmean(),sd(),length() - Inspect any data frame with
head()andstr() - Pull out a column with
$
Next: turning raw columns into the descriptive statistics every results section starts with.
