Lists in R
Heterogeneous containers, the shape of every R model object.
model <- list(
name = "linear",
coefficients = c(intercept = 1.5, slope = 0.8),
converged = TRUE
)
name <- model$name
coefs <- model[["coefficients"]]
subset <- model["converged"]
model$rss <- 12.4
fields <- names(model)
flat <- unlist(model$coefficients)
How it works
$and[[ ]]extract an element's value.- Single brackets return a sub-list instead.
- Assigning a new name grows the list.
Keywords and builtins used here
clistnamesunlist
The run, in numbers
- Lines
- 13
- Characters to type
- 257
- Tokens
- 64
- Three-star pace
- 90 tpm
At the three-star pace of 90 tokens a minute, this run takes about 43 seconds.
Step 2 of 2 in Matrices & lists, step 16 of 20 in Language basics.