Welcome to Data Science with R!
What You’ll Learn Today
Get ready for an amazing journey into data science! 🌟
Data Analyst: Works with data to find trends and create reports. They use tools like Excel, SQL, and visualization software.
Data Scientist: Builds models to predict outcomes. They use programming languages like Python or R and machine learning techniques.
Data Engineer: Designs and builds systems to collect and store data. They work with databases and big data tools.
Machine Learning Engineer: Creates algorithms that learn from data. They focus on deploying models in real-world applications.
Business Intelligence Analyst: Translates data into business insights. They create dashboards and help decision-makers.
Programming: Learn Python or R. These languages help you clean and analyze data.
Statistics: Understand basic statistics to interpret data correctly.
Data Visualization: Use tools like Tableau or Power BI to create clear charts.
Machine Learning: Know how to build and test predictive models.
Communication: Explain your findings clearly to non-technical people.
Problem Solving: Think critically to find the best solutions.
Note
Plan your work, work your plan!
Important
Salary info: USNews
R Foundations
Advanced Topics
ML and Beyond
Today we start with the fundamentals — the building blocks of everything else!
Important
R: Purpose-Built for Data
R was designed specifically for statistical computing and data analysis:
The Big Picture: You will learn R for data analysis, but we will also introduce some Python later to show you how they complement each other.
While you are waiting for the install to complete, here’s more fun facts about R and why it is a great language to learn for data science!
R is a programming language for statistical computing and data analysis.
RStudio is an integrated development environment (IDE) for R. It provides a user-friendly interface for writing and executing R code.
Download R
Visit CRAN Download Site
Click “Download R”
Choose your CRAN mirror (if asked, choose one close to your geographical location)
Select your OS, download the installer, and follow the installation instructions
Latest version: R 4.5.x: See R Project
Download RStudio
Note: RStudio is not the programming language. Instead, it is similar to an IDE that manages R programming. <!– RStudio gives you:
Script editor
Console
Plots & visualizations
Environment viewer –>
The Four Panes
Top-Left: Script Editor — Write & save your code
Bottom-Left: Console — Execute commands interactively
Top-Right: Environment — See your variables & data
Bottom-Right: Files, Plots, Help, Packages
Try It Out! Open RStudio and type in the console:
Pro Tip: The console shows > when ready for input. If you see +, R is waiting for you to complete a command!
Important
Variables Store Information
In R, we use <- (or =) to assign values to variables
Tip
Style Guide: Use <- for assignment (not =). Use descriptive names with underscores: student_count, not sc or studentCount.
Numeric
Logical
Vectors: Collections of Values
A vector is a sequence of elements of the same type. This is R’s most fundamental data structure!
# Creating vectors with c() (combine function)
ages <- c(25, 30, 22, 35, 28)
names <- c("Alice", "Bob", "Carol", "David", "Eve")
passed <- c(TRUE, TRUE, FALSE, TRUE, TRUE)
# Vectors can only hold ONE type
mixed <- c(1, 2, "three", 4) # Everything becomes character!
class(mixed) # "character"
# Sequences
nums1 <- 1:10 # 1 2 3 4 5 6 7 8 9 10
nums2 <- seq(0, 1, by = 0.1) # 0.0 0.1 0.2 ... 1.0
nums3 <- seq(1, 10, length = 5) # 1.00 3.25 5.50 7.75 10.00
# Repetition
zeros <- rep(0, 5) # 0 0 0 0 0
pattern <- rep(c(1, 2), 3) # 1 2 1 2 1 2Vectorization: R’s Secret Weapon
Operations apply to ALL elements at once — no loops needed!
# Create a vector
prices <- c(10, 20, 30, 40, 50)
# Vectorized operations (work on ALL elements!)
prices * 2 # 20 40 60 80 100
prices + 5 # 15 25 35 45 55
prices / 10 # 1 2 3 4 5
sqrt(prices) # 3.16 4.47 5.48 6.32 7.07
# Element-wise operations
prices1 <- c(10, 20, 30)
prices2 <- c(5, 10, 15)
prices1 + prices2 # 15 30 45
prices1 * prices2 # 50 200 450
# Statistical functions
mean(prices) # 30
median(prices) # 30
sum(prices) # 150
sd(prices) # Standard deviation: 15.81Indexing: Getting Specific Elements
R uses 1-based indexing (unlike Python’s 0-based)
Positive Indexing
Basic Math
Comparisons
What We Learned Today
R & RStudio setup Variables and data types (numeric, character, logical) Vectors: creation, operations, indexing Arithmetic, comparison, and logical operations Interactive tools for hands-on learning
Up Next
Practice: Create vectors, try operations, experiment!
Install: Make sure R and RStudio are working
Preview: We’ll explore data structures (lists, data frames, matrices)
x <- c(10, 20, 30, 40, 50) mean(x[x > 25])
x after running: x <- c(1, 2, "3")?x <- c(10, 20, 30) and y <- c(1, 2), what does x + y produce?scores <- c(85, 92, 78, 95, 88), which code gets scores above 90?
# Method 1: Using seq()
evens <- seq(2, 20, by = 2)
mean(evens)
# Method 2: Using sequence and filtering
evens <- (1:10) * 2
mean(evens)
# Result: 11
Variable Assignment
Vector Creation
Vector Access