typestar

Data frames in R

The rectangular table at the center of R analysis.

people <- data.frame(
  name = c("ada", "grace", "kay"),
  score = c(95, 88, 92),
  stringsAsFactors = FALSE
)

shape <- dim(people)
columns <- names(people)
first_rows <- head(people, 2)
structure <- str(people)

people$passed <- people$score >= 90
one_cell <- people[2, "score"]

How it works

  1. data.frame builds one column by column.
  2. dim, names, head, and str inspect it.
  3. df$new <- ... adds a computed column.

Keywords and builtins used here

The run, in numbers

Lines
13
Characters to type
274
Tokens
77
Three-star pace
90 tpm

At the three-star pace of 90 tokens a minute, this run takes about 51 seconds.

Type this snippet

Step 1 of 3 in Building & inspecting, step 1 of 8 in Data frames in base R.

Next →