Skip to content
Lists and Named Lists
step 1/5

Reading — step 1 of 5

Learn

~1 min readData Frames

Vectors hold one type. Lists hold mixed types — they're R's heterogeneous container.

person <- list(name = "Ada", age = 36, hobbies = c("math", "engines"))
person$name              # "Ada"
person[["age"]]          # 36
person$hobbies[1]        # "math"

Note [[ ]] vs [ ]:

  • person[["age"]] returns the value (36, an integer)
  • person["age"] returns a list of length 1 (a sub-list)

Lists are how R handles heterogeneous returns. A lm() regression result is a list of coefficients, residuals, fitted values, etc.

Data frames (next lesson) are special lists where every element is a vector of equal length — a tabular structure.

Discussion

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

Sign in to post a comment or reply.

Loading…