Selecting multiple elements with [

Special way of subsetting for data frames: df[rows, cols].

Here, rows and cols are vectors (indices, logical, names) to subset the data frame.

Column selection: cf. select(), relocate()

df <- data.frame(x = 1:2, y = c("k", "l"), z = c(FALSE, TRUE))
df
##   x y     z
## 1 1 k FALSE
## 2 2 l  TRUE
df[1, c("x", "y")]
##   x y
## 1 1 k
df[, c("z", "y")]
##       z y
## 1 FALSE k
## 2  TRUE l