R
Completed
-
Section 1: Getting Started
-
Section 2: Core Syntax
-
Section 3: Data Structures
-
Section 4: Data Manipulation
-
Section 5: Visualization and Statistics
-
Section 6: Advanced R
-
Section 7: Practical Projects
-
Section 8: Interview Practice
-
Section 9: More Practice Exercises
-
Section 10: Shiny Apps in Depth
-
Section 11: More Data Wrangling
-
Section 12: Tidyverse Deep Dive
-
Section 13: Statistical Modeling Deep Dive
-
Section 14: Machine Learning in R
-
Section 15: R Visualization Deep Dive
-
Section 16: R Package Development Deep Dive
-
Section 17: R for Reproducible Research
-
Section 18: R and Databases
-
Section 19: R Performance Optimization
-
Section 20: Bioinformatics and Specialized R
-
Section 21: More Shiny Practice
-
Section 22: More Practice Exercises
-
Section 23: R Data Structures Deep Dive
-
Section 24: More Interview and Review
-
Section 25: R for Business Analytics
-
Section 26: R Text Mining and NLP
-
Section 27: R Spatial Data Analysis
-
Section 28: R Deep Learning
-
Section 29: Advanced Statistical Techniques
-
Section 30: R Object Systems Deep Dive
-
Section 31: R Environments and Metaprogramming
-
Section 32: R for Finance
-
Section 33: R for Clinical and Health Data
-
Section 34: More Shiny Advanced Practice
-
Section 35: R Data Cleaning Deep Dive
-
Section 36: R Reporting Automation
-
Section 37: More Practical Projects Round 2
-
Section 38: R Ecosystem and Career
-
Section 39: More Visualization Practice
-
Section 40: R for Experimentation
-
Section 41: R for Genomics and Bioinformatics Deep Dive
-
Section 42: R for Marketing Analytics
-
Section 43: R Data Import/Export Deep Dive
-
Section 44: R String Processing Deep Dive
-
Section 45: R for Actuarial and Insurance Analytics
-
Section 46: R Testing and Quality Assurance Deep Dive
-
Section 47: R Version Control and Collaboration
-
Section 48: R Advanced Functional Programming
-
Section 49: R for Supply Chain and Operations
-
Section 50: More Practice Exercises Round 3
-
Section 51: R Dashboards and BI Integration
-
Section 52: R Data Governance and Ethics
-
Section 53: More Modeling Practice
-
Section 54: R Final Capstone Projects
-
Section 55: R for Sports Analytics
-
Section 56: More Interview Practice Round 2
-
Section 57: R Networking and APIs
-
Section 58: R for Environmental Science
-
Section 59: R Notebook and Documentation Practices
-
Section 60: More Data Wrangling Mastery
-
Section 61: R for A/B Testing at Scale
-
Section 62: R Package Ecosystem Deep Dive
38: Common R Interview Questions for Data Roles
Think of a technical interview for a data role like a cooking audition for a high-end restaurant. The head chef isn't just checking if you know that salt makes things salty—they already assume you know the basics. What they're actually looking for is how you organize your station, how you handle a sudden mess on the counter, and whether you use the most efficient tool for the job. If you try to chop a hundred carrots one by one with a tiny paring knife, you might get the job done, but the chef will know you don't actually understand how a professional kitchen works.
In R, the "paring knife" is the for loop, and the "professional chef's knife" is vectorization. When an interviewer asks you a technical question, they aren't just looking for a result that prints to the console; they're looking for "R-native" thinking. They want to see if you can manipulate data without fighting the language.
The Vectorization Trap
I've seen plenty of brilliant analysts fail interviews because they wrote R like it was Java or Python. A classic interview question is: "How would you calculate the square of every number in a vector of a million elements?"
If you start writing a for loop, you've already lost points. In R, the "correct" answer is to lean into vectorization. It's the difference between telling a waiter to bring ten drinks one by one, or telling them to bring a tray of ten drinks. The tray is faster and requires less effort from the server.
# The "Paring Knife" approach (Avoid this in interviews)
results <- c()
for (i in 1:length(my_vector)) {
results[i] <- my_vector[i]^2
}
# The "Chef's Knife" approach (Do this)
results <- my_vector^2
If you're asked why this matters, tell them about memory allocation. In the loop version, R has to resize the results vector every single time you add an element. That's a performance nightmare. Vectorized operations happen in C under the hood, which is why they're lightning-fast.
The 'Apply' Family Confusion
You will almost certainly be asked about the difference between lapply, sapply, and apply. This is a litmus test for whether you understand how R handles data structures. I like to think of these as different ways of "packaging" your results.
- lapply: The "L" stands for List. It always returns a list, regardless of what's inside. It's the safest bet because it doesn't try to guess what you want; it just gives you everything back in a consistent container.
- sapply: The "S" stands for Simplify. It tries to be helpful. If it sees that every element in the resulting list is a single number, it'll automatically turn that list into a vector for you. It's great for interactive work, but in a production pipeline, "guessing" can lead to bugs.
- apply: This is for matrices or data frames. It requires you to specify a margin (1 for rows, 2 for columns).
Pro tip: If an interviewer asks which one you prefer, mention that vapply is actually the gold standard for production code because it forces you to specify the output type, preventing the "surprise" type-changes that sapply can cause.
Dealing with the Dreaded NA
In the real world, data is filthy. Interviewers love to throw NA values at you to see if you're paying attention. A common "gotcha" is asking you to calculate the mean of a column that contains a few missing values.
# This will return NA, and the interviewer will smile
mean(my_data$salary)
# This shows you actually know how to handle data
mean(my_data$salary, na.rm = TRUE)
But don't stop there. To really impress them, talk about the philosophy of NA. Ask them: "Do these NAs represent missing data, or are they logically null?" Showing that you think about the meaning of the missingness, rather than just slapping na.rm = TRUE on everything, moves you from "coder" to "data scientist."
Tidying Your Logic
Finally, be prepared to discuss the difference between a data.frame and a tibble. Most people just say "tibbles are better," but that's a weak answer. The real difference is in the defaults. Tibbles don't change variable types (no more accidental factors!) and they don't print 10,000 rows to your console and crash your RStudio session. They are designed to be "lazy and complaining"—they don't do things silently; they tell you when something is wrong.
📋 Practical Task
Refactoring the Slow Loop for a Technical Screening
You've been handed a snippet of code from a junior analyst that is running incredibly slowly on a dataset of 500,000 customer records. The goal is to create a new column called category based on the spend column: if spend is over 1000, it's "High"; otherwise, it's "Low".
The current code looks like this:
# The slow way
df$category <- NA
for (i in 1:nrow(df)) {
if (df$spend[i] > 1000) {
df$category[i] <- "High"
} else {
df$category[i] <- "Low"
}
}
Your Task: Rewrite this logic using a vectorized approach. You can use either base R (like ifelse()) or a dplyr function (like if_else() or case_when()). Your solution should eliminate the for loop entirely to ensure it would pass a technical interview review.
There are no comments for now.