📊 R — Learn From Zero

Playground: rdrr.io | Replit R — click, type, run.

What is R?

R is a statistical computing language beloved by data scientists. Excellent for analysis, visualization, and reporting.

  • Data analysis & statistics
  • Visualization (ggplot2)
  • Academic research
  • Reporting (R Markdown)

Run Online — No Install

Use the playground links above.

🟢 Beginner — Core Basics

Your First Program

r
print("Hello, world!")

Use print() or just type the value.

Variables

r
name <- "Ada"
age <- 36
height <- 1.78
is_student <- TRUE

Assignment with <-.

If / Else

r
age <- 18
if (age >= 18) {
  print("Vote")
} else {
  print("Too young")
}

Curly braces group statements.

Loops

r
for (i in 1:5) print(i)
n <- 3
while (n > 0) { print(n); n <- n - 1 }

Vectors drive iteration.

Functions

r
greet <- function(name) {
  paste("Hello,", name, "!")
}
greet("World")

Defined with function().

Vectors & Data Frames

r
v <- c(1, 2, 3)
df <- data.frame(name = c("Ada"), age = c(36))

Vectors are the core data type.

🟡 Intermediate — Building Real Programs

dplyr

r
library(dplyr)
df %>% filter(age > 30) %>% summarise(avg = mean(age))

Grammar of data manipulation.

ggplot2

r
library(ggplot2)
ggplot(df, aes(x = age)) + geom_histogram()

Layered grammar of graphics.

apply Family

r
sapply(1:5, function(x) x * 2)

Vectorized iteration.

Read Data

r
data <- read.csv("file.csv")
head(data)

Import CSV/Excel/JSON easily.

Formulas

r
model <- lm(age ~ height, data = df)
summary(model)

Formula syntax for stats.

🔴 Advanced — Pro Concepts

purrr

r
library(purrr)
map(list(1, 2), ~ .x * 2)

Functional programming toolkit.

S3 Objects

r
myobj <- structure(1, class = "myclass")
print.myclass <- function(x) cat("val:", x, "\n")

R's simplest OO system.

Parallel

r
library(parallel)
mclapply(1:4, function(x) x^2, mc.cores = 2)

Parallelize computations.

Shiny

r
library(shiny)
ui <- fluidPage("Hello")
server <- function(input, output) {}
shinyApp(ui, server)

Build interactive web apps.

What's Next?

  • Build a tiny project: Calculator, To-Do App, Weather Widget
  • Read the official docs and a good book
  • Solve Exercism exercises
  • Join a community & share your code

Practice daily for 20 minutes. Consistency > intensity.