This reference starts with installing R and RStudio, then moves through the language, data cleaning, visualisation, statistics, modelling, reporting and Shiny. Work through the sections in order if you are new to R, or use the contents panel to jump directly to the topic you need.
Beginner to intermediateAbout 10 minutesLast updated August 2026
A note from the author
I’m Imonikhe Ayeni. I use R for statistical analysis, research and reporting work.
I put this reference together so learners can find the main ideas and examples in one place.
No matching sections were found. Try a broader search term.
01
Installing R and RStudio
R is the programming language. RStudio is an integrated development environment that makes R easier to write, run, organise and debug. Install R first, then install RStudio Desktop.
Windows
1. Open the CRAN website.
2. Choose “Download R for Windows”.
3. Select “base”.
4. Download the current Windows installer.
5. Run the installer and accept the standard options.
6. Download RStudio Desktop from Posit.
7. Install and open RStudio.
8. In the Console, run: R.version.string
macOS
1. Open the CRAN website.
2. Choose “Download R for macOS”.
3. Select the installer that matches your Mac and macOS version.
4. Run the downloaded package.
5. Download and install RStudio Desktop.
6. Open RStudio and run: R.version.string
Linux: Ubuntu or Debian
sudo apt update
sudo apt install r-base r-base-dev
# Verify
R --version
# Start R
R
# Exit R
q()
Test R inside RStudio
R.version.string
getwd()
message("R is installed and working.")
02
Understanding RStudio
RStudio normally contains four panes: the source editor, console, environment/history, and files/plots/packages/help. Write reusable code in an R script rather than relying only on the console.
Create your first script
# File > New File > R Script
name <- "Imonikhe"
message <- paste("Welcome to R,", name)
print(message)
Create an R project
1. Select File > New Project.
2. Choose New Directory.
3. Choose New Project.
4. Give the project a meaningful name.
5. Keep scripts, data and outputs inside the project.
6. Use relative paths instead of changing the working directory manually.
R commonly uses the assignment operator <-. Objects can store numbers, text, Boolean values, dates, vectors, tables, functions and models.
Variables and data types
name <- "Imonikhe"
age <- 38L
height <- 1.78
is_learning <- TRUE
missing_value <- NA
class(name)
class(age)
class(height)
class(is_learning)
Arithmetic and comparisons
a <- 10
b <- 3
a + b
a - b
a * b
a / b
a %% b
a ^ b
a > b
a == 10
a != b
Strings
message <- "R for Data Science"
tolower(message)
toupper(message)
nchar(message)
grepl("Data", message)
paste("Learning", "R")
paste0("Score: ", 95)
05
Vectors, factors, lists and matrices
A vector stores values of the same basic type. Factors represent categories. Lists can contain different object types. Matrices store two-dimensional values of one type.
ggplot2 builds charts in layers: data, aesthetic mappings, geometric marks and labels.
Scatter plot
library(ggplot2)
ggplot(data, aes(x = age, y = score)) +
geom_point() +
labs(
title = "Age and Score",
x = "Age",
y = "Score"
) +
theme_minimal()
Bar chart
ggplot(distribution, aes(
x = gender,
y = percentage
)) +
geom_col() +
labs(
title = "Participant Distribution",
x = "Gender",
y = "Percentage"
) +
theme_minimal()
Box plot
ggplot(data, aes(
x = response_method,
y = score
)) +
geom_boxplot() +
labs(
title = "Scores by Response Method",
x = "Response method",
y = "Score"
) +
theme_minimal()
15
Statistical analysis
R was designed for statistical computing and includes many tests in base R.
Shiny creates interactive web applications directly from R. A basic app contains a user interface and a server function.
Minimal Shiny application
library(shiny)
ui <- fluidPage(
titlePanel("Score Explorer"),
sliderInput(
"minimum_score",
"Minimum score",
min = 0,
max = 100,
value = 50
),
tableOutput("filtered_table")
)
server <- function(input, output, session) {
output$filtered_table <- renderTable({
data |>
filter(score >= input$minimum_score)
})
}
shinyApp(ui, server)
20
Good R habits
Clear projects, readable pipelines, documented assumptions and reproducible package environments make work easier to review and maintain.
Recommended practices
• Use R projects and relative paths.
• Prefer clear object names over x, y or temp.
• Keep raw data unchanged.
• Put reusable logic in functions.
• Use set.seed() for reproducible random processes.
• Validate joins by checking row counts and unmatched keys.
• Comment why a decision was made, not only what the code does.
• Store package versions for important projects.