R is one of the two dominant languages in data science (alongside Python), and it’s the go-to tool for statisticians, researchers, and anyone who needs publication-quality visualizations or rigorous statistical analysis. This guide gets you productive with R in 2026.
Why Learn R in 2026?
R was built by statisticians for statistical computing. Its strengths include an unmatched ecosystem for statistical modeling (linear mixed models, survival analysis, Bayesian inference), the best data visualization library in any language (ggplot2), and deep integration with academic research. Many data science roles — especially in pharma, finance, and academia — still require R. And increasingly, data scientists use both R and Python, choosing whichever tool is better for the specific task.
R Basics
Install R from CRAN and RStudio as your IDE. Here are the fundamentals:
# Variables
x <- 42 # preferred assignment operator
name <- "Alice"
# Vectors (R's core data structure)
scores <- c(85, 92, 78, 95, 88)
mean(scores) # 87.6
sd(scores) # 6.54
# Data frame
df <- data.frame(
name = c("Alice", "Bob", "Carol"),
score = c(85, 92, 78),
pass = c(TRUE, TRUE, FALSE)
)
str(df)
The Tidyverse – Modern R Data Science
The tidyverse is a collection of R packages that share a consistent grammar for data manipulation and visualization. Install it once:
install.packages("tidyverse")
library(tidyverse)
The core packages are dplyr (data manipulation), ggplot2 (visualization), tidyr (reshaping), readr (reading files), and purrr (functional programming).
Data Manipulation with dplyr
library(dplyr)
# Load built-in dataset
data(mpg)
mpg |>
filter(cyl == 6, year == 2008) |>
select(manufacturer, model, hwy, cty) |>
group_by(manufacturer) |>
summarise(
avg_hwy = mean(hwy),
count = n()
) |>
arrange(desc(avg_hwy))
The pipe operator |> (or %>% from magrittr) chains operations left-to-right, making code read like a sentence: “take mpg, then filter, then select, then group, then summarise.”
Data Visualization with ggplot2
library(ggplot2)
ggplot(mpg, aes(x = displ, y = hwy, colour = class)) +
geom_point(alpha = 0.7, size = 2) +
geom_smooth(method = "lm", se = FALSE) +
labs(
title = "Engine Displacement vs Highway MPG",
subtitle = "2008 vehicles by class",
x = "Engine displacement (litres)",
y = "Highway fuel economy (mpg)"
) +
theme_minimal()
ggplot2 uses a layered grammar of graphics — you add layers (geom_point, geom_line, geom_bar) on top of a base aesthetic mapping. This makes complex plots composable and consistent.
Statistical Modeling in R
# Linear regression
model <- lm(hwy ~ displ + cyl + year, data = mpg)
summary(model)
# Logistic regression
df$pass <- as.factor(df$pass)
logit <- glm(pass ~ score, data = df, family = binomial)
summary(logit)
R’s built-in lm() and glm() functions are incredibly powerful and output detailed summaries including coefficients, p-values, R², AIC, and residual diagnostics.
Machine Learning with caret / tidymodels
library(tidymodels)
# Split data
split <- initial_split(mtcars, prop = 0.8)
train <- training(split)
test <- testing(split)
# Define and train a random forest
rf_spec <- rand_forest(trees = 500) |>
set_engine("ranger") |>
set_mode("regression")
rf_fit <- rf_spec |> fit(mpg ~ ., data = train)
# Predict and evaluate
preds <- predict(rf_fit, test)
rmse_vec(test$mpg, preds$.pred)
R vs Python — Which Should You Learn?
Learn Python first if you want to do deep learning, MLOps, or production engineering. Learn R first (or alongside Python) if your work is statistics-heavy, you work in academia or pharma, or you need the best visualization tools. In practice, the most valuable data scientists in 2026 are comfortable with both — using Python for model deployment and R for statistical rigor and reporting.
Conclusion
R’s tidyverse ecosystem makes data manipulation and visualization genuinely enjoyable. Its statistical modeling capabilities are unmatched. Whether you’re a beginner choosing your first language or a Python data scientist adding R to your toolkit, the investment in learning R pays dividends in analytical depth and research credibility.



