Selecting single elem. with [[
and $
Extracting a single element with [[
or $
returns the element, not a subset of the input object.
Hence the element is always the simplest representation.
For a vector, this is a scalar (vector of length 1).
[[
: takes a position or a name (e.g.x[[1]]
orx[["apple"]]
)$
: only takes a name (e.g.x$apple
)- equivalent is
dplyr::pull()
- equivalent is