Skip to content

Instantly share code, notes, and snippets.

@eddjberry
Last active January 24, 2019 16:11
Show Gist options
  • Save eddjberry/93c8e151db133adbfc720cbfc87dc7bf to your computer and use it in GitHub Desktop.
Save eddjberry/93c8e151db133adbfc720cbfc87dc7bf to your computer and use it in GitHub Desktop.
Different return types for selecting columns from a tibble
# create a tibble----------------------
tbl <- tibble::tibble(x = letters[1:5],
y = letters[5:1])
# returns a tibble --------------------
dplyr::select(tbl, x)
tbl[1]
tbl[, 1]
tbl["x"]
tbl[, "x"]
subset(tbl, select = "x")
# returns a vector --------------------
dplyr::pull(tbl, x)
tbl[, 1, drop = TRUE]
tbl[[1]]
tbl[, "x", drop = TRUE]
tbl[["x"]]
tbl$x
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment