Data frames are the standard tabular structure — a list of equal-length vectors. Each column can have a different type. Essential inspection functions: str(), summary(), head(), dim(), colnames().
# Create
df <- data.frame(
species = c("Gobio gobio", "Cottus perifretum", "Leuciscus leuciscus"),
length_mm = c(82, 65, 110),
weight_g = c(5.2, 3.1, 14.8),
threatened = c(FALSE, TRUE, FALSE)
)
# Inspect
str(df)
head(df, 2)
dim(df) # rows, columns
nrow(df); ncol(df)
colnames(df)
summary(df)
# Access columns
df$species
df[["length_mm"]]
# Add / modify column
df$bmi <- df$weight_g / (df$length_mm / 10)^2
# Filter rows (base R)
df[df$threatened == TRUE, ]
subset(df, length_mm > 70)