Skip to content
Data Frames — R's Tables
step 1/4

Reading — step 1 of 4

Learn

~1 min readData Frames

A data frame is the workhorse of R analysis: a list of equal-length vectors, displayed and used as a table.

df <- data.frame(
    name = c("Ada", "Linus", "Grace"),
    age = c(36, 53, 85),
    field = c("math", "systems", "compilers")
)

nrow(df)        # 3
ncol(df)        # 3
names(df)       # "name" "age" "field"

df$age          # column access (returns vector)
df[1, ]         # row 1 (entire)
df[, "name"]    # column by name
df[df$age > 40, ]   # filter rows

The pattern df[condition, ] is THE filtering idiom — read it as [which rows? all columns].

For anything beyond basic filtering, the dplyr package offers filter, select, mutate, summarise, group_by — but base R takes you a long way.

Discussion

Ask a question, share an insight, or help someone who’s stuck.

Sign in to post a comment or reply.

Loading…