100% Free Forever
AI-Powered Learning
Industry Expert Content
Certificates & Badges
Learn At Your Own Pace

R Cheat Sheet

R Cheat Sheet

R syntax, vectors, data frames, and core statistical functions for data analysis, wrangling, and visualization.

2 PagesBeginnerApr 12, 2026

Basic Syntax

Assignment, control flow, and printing.

r
age <- 30                 # assignment operatorname <- "Ada"pi_val <- 3.14159is_fun <- TRUEif (age >= 18) {  print(paste(name, "is an adult"))}for (i in 1:5) {  print(paste("Count:", i))}

Vectors & Data Frames

R's core data structures.

r
nums <- c(5, 3, 1, 4, 2)      # numeric vectorsorted <- sort(nums)          # 1 2 3 4 5nums[2]                       # 3 (1-indexed)df <- data.frame(  name = c("Alice", "Bob"),  age = c(30, 25))df$age                        # 30 25df[df$age > 26, ]              # rows where age > 26

Statistical Functions

Common base-R statistics functions.

  • mean(x)- arithmetic average of a numeric vector
  • median(x)- middle value of a sorted vector
  • sd(x)- sample standard deviation
  • summary(x)- min, quartiles, mean, and max of a vector/data frame
  • lm(y ~ x)- fits a linear regression model
  • table(x)- frequency counts of categorical values
  • is.na(x)- returns TRUE for missing (NA) values

The Apply Family

Vectorized iteration over lists and matrices.

r
nums <- list(1:3, 4:6, 7:9)sapply(nums, sum)              # 6 15 24 (simplified vector)lapply(nums, mean)             # list of meansvapply(nums, sum, numeric(1))  # 6 15 24 (type-checked)m <- matrix(1:6, nrow = 2)apply(m, 1, sum)                # row sumsapply(m, 2, sum)                # column sums
Pro Tip

Use vectorized operations (nums * 2) instead of for-loops in R — the interpreter is optimized for vector math and loops are comparatively slow.

Was this cheat sheet helpful?

Explore Topics

#RCheatSheet#Programming#Beginner#BasicSyntax#VectorsDataFrames#StatisticalFunctions#TheApplyFamily#Functions#CheatSheet#SkillVeris
Advertisement
Sri Hayavadhana Info-Tech

Professional Web Designing Services

  • Responsive Websites
  • E-commerce Solutions
  • SEO Friendly Design
  • Fast & Secure
  • Support & Maintenance
Get a Free Quote

Share this Cheat Sheet