Data Frames
In this page:
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
df <- data.frame(
name = c("Alice", "Bob", "Cara"),
age = c(30, 25, 40)
)
print(df)
cat("Ages:", df$age, "\n")
print(df[1, ])
Login to try C/C++/Java/PHP code in the editor
🔒
Chapter Quiz — Complete all 7 topics to unlock
0/7 topics done
Complete these topics first: