Selecting multiple elements with [

  • using vector of element names (3/3)

Data frame example:

x <- data.frame(apple = c(10, 15), banana = c(20, 25), melon = c(30, 35))
x
##   apple banana melon
## 1    10     20    30
## 2    15     25    35
x[c("melon", "apple")]
##   melon apple
## 1    30    10
## 2    35    15