← Back to R Course | Chapter 7: Data Structures | Lesson 3 of 7

Data Frames

In this page:

  1. Data Frames

Data Frames

A data frame is R's table-like structure for tabular data, where each column can have a different type but all columns have the same number of rows -- similar to a spreadsheet or SQL table. It's created with data.frame() and is the primary structure used for data analysis in R. Columns are accessed with $ and rows/columns with [row, col] indexing.

Note: Use str(df) to quickly see a data frame's column names, types, and a preview of its values.

Example: Data Frames

markup
df <- data.frame(
  name = c("Alice", "Bob", "Cara"),
  age = c(30, 25, 40)
)

print(df)
cat("Ages:", df$age, "\n")
print(df[1, ])
🔒

Chapter Quiz — Complete all 7 topics to unlock

0/7 topics done

Complete these topics first:

Login to run this code

C/C++/Java/PHP execution requires a free account. Your code is saved — you'll land right back in the editor after logging in.