CHAPTER 10
Beginner
Lists and Data Frames
Updated: May 18, 2026
5 min read
# CHAPTER 10
Lists and Data Frames in R
1. Chapter Introduction
Lists hold mixed types; data frames hold tabular data. Together they're the foundation of all real-world R data analysis. This chapter masters both structures and builds an employee records management system.2. Lists
r
3. Data Frames
r
4. Data Frame Manipulation
r
5. Mini Project: Employee Records System
r
6. Common Mistakes
-
employee[4]vsemployee[[4]]:[4]returns a list with one element.[[4]]returns the element itself. Use[[]]to extract content.
-
stringsAsFactorsdefault: In older R (<4.0), character columns were automatically converted to factors. In R 4.0+, default isFALSE. Be explicit when needed.
7. MCQs
Question 1
df$column vs df[["column"]]?
Question 2
list[[2]] vs list[2]?
Question 3
str(df) shows?
Question 4
rbind() combines data frames?
Question 5
aggregate(salary ~ dept, data, mean) computes?
Question 6
df$col <- NULL does?
Question 7
subset(df, cond, select=cols) is equivalent to?
Question 8
names(df)[3] <- "new_name" renames?
Question 9
summary(df) on numeric columns shows?
Question 10
Ordered data frame with order(-salary)?
8. Interview Questions
- Q: What is the difference between a list and a data frame in R?
- Q: How do you filter and select specific columns from a data frame?
9. Summary
Lists: ordered collections of any type, accessed with$name or [[i]]. Data frames: rectangular tables with named columns — R's primary data analysis structure. Key operations: subset(), aggregate(), rbind(), cbind(), order(). str() for structure overview, summary() for statistics. df$col <- NULL removes columns. In R 4.0+, strings are not auto-converted to factors.
10. Next Chapter Recommendation
In Chapter 11: Working with Strings in R, we master string manipulation using both base R and thestringr package from the tidyverse.