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

R for Data Science Cheat Sheet

R for Data Science Cheat Sheet

Introduces R's core syntax, vectors, data frames, and the tidyverse ecosystem for foundational data science workflows.

2 PagesBeginnerMar 2, 2026

Vectors, Types & Functions

The fundamental building blocks of R.

r
# Vectors and basic typesx <- c(1, 2, 3, 4, 5)names <- c("alice", "bob", "carol")is_active <- c(TRUE, FALSE, TRUE)# Vectorized arithmeticx * 2x[x > 2]              # logical indexing# Functionssquare <- function(n) {  return(n^2)}sapply(x, square)      # apply over a vector# Control flowif (mean(x) > 3) {  print("above average")} else {  print("below average")}

Data Frames

Create, inspect, and filter tabular data.

r
df <- data.frame(  name = c("Alice", "Bob", "Carol"),  age = c(25, 30, 35),  score = c(88.5, 92.1, 79.3))str(df)          # structure/typessummary(df)      # summary statisticshead(df, 2)df$age                    # access a columndf[df$score > 80, ]       # filter rowsdf[order(-df$score), ]    # sort descending

Base R Functions

Frequently used built-in functions.

  • c()- Combines values into a vector
  • str()- Displays the structure (types, dimensions) of an object
  • sapply()/lapply()- Apply a function over a vector/list; sapply simplifies to a vector, lapply returns a list
  • which()- Returns indices where a logical condition is TRUE
  • table()- Builds a contingency/frequency table of categorical values
  • NA handling- is.na() tests for missing values; na.rm=TRUE in functions like mean() ignores them

The Tidyverse Ecosystem

Packages that make up R's modern data science toolkit.

  • tidyverse- Collection of packages (dplyr, ggplot2, tidyr, readr, purrr) sharing a common design philosophy
  • readr::read_csv()- Faster, type-consistent CSV reader that returns a tibble
  • tibble- Modern re-implementation of data.frame with stricter, more predictable behavior
  • %>% / |>- Pipe operators that chain function calls left-to-right for readable transformations
  • RStudio- The standard IDE for R, with an integrated console, plots pane, and package management
Pro Tip

Use the native pipe |> (R 4.1+) or magrittr's %>% to chain transformations instead of nesting function calls - df |> filter(score > 80) |> arrange(desc(score)) reads top-to-bottom in the order operations actually happen.

Was this cheat sheet helpful?

Explore Topics

#RForDataScience#RForDataScienceCheatSheet#DataScience#Beginner#VectorsTypesFunctions#DataFrames#BaseRFunctions#TheTidyverseEcosystem#MachineLearning#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