An overview of the R programming language, its features, and how it is used in the context of data science.
Introduction to R Programming
Quick‑reference guide for beginners
| Aspect | Description |
|---|---|
| Type | Open‑source language & environment for statistical computing and graphics |
| Origin | Developed in 1993 by Ross Ihaka & Robert Gentleman (University of Auckland) |
| License | GNU GPL (free to use, modify, distribute) |
| Core Strengths | Data manipulation, statistical modeling, reproducible research, high‑quality visualizations |
| Community | CRAN (Comprehensive R Archive Network) hosts > 19,000 packages; active mailing lists, Stack Overflow, R‑Bloggers |
| Step | Action |
|---|---|
| Install R | Download from https://cran.r-project.org (Windows, macOS, Linux) |
| Install an IDE | RGui (basic), RStudio (most popular), VS Code with R extension, or Jupyter notebooks |
| Run a script | Rscript myfile.R (command line) or click Run in the IDE |
| Package management | install.packages("pkg") – install library(pkg) – load remove.packages("pkg") – uninstall |
| Category | Example | Notes |
|---|---|---|
| Comments | # This is a comment |
Whole line or trailing comment |
| Assignment | x <- 10 or x = 10 |
<- is idiomatic; = works inside function calls |
| Vectors | v <- c(1, 2, 3) |
Homogeneous; recycling rules apply |
| Sequences | seq(1, 10, by = 2) or 1:10 |
Shortcut for integer sequences |
| Matrices | m <- matrix(1:9, nrow = 3, byrow = TRUE) |
2‑D, column‑major storage |
| Lists | lst <- list(name="Alice", age=30, scores=c(90,85)) |
Heterogeneous, can contain any object |
| Data frames | df <- data.frame(id=1:3, gender=c("F","M","F")) |
Tabular data; each column is a vector |
| Factors | f <- factor(c("yes","no","yes")) |
Categorical data with levels |
| Logical | TRUE, FALSE |
Used for subsetting, conditionals |
| Missing values | NA, NaN, NULL |
is.na(), is.nan(), is.null() to test |
v[2] # 2nd element
v[ c(1,3) ] # elements 1 and 3
v[ v > 2 ] # conditional subset
df[1:2, "age"] # rows 1‑2, column "age"
df$age # shortcut for column
df[[ "age" ]] # same as df$age
x <- 1:5
y <- x * 2 # element‑wise multiplication
z <- x + y # addition
All arithmetic is automatically vectorized; no explicit loops needed.