Search code examples
rdataframetibble

Selecting a single column from a tibble still returns a tibble instead of a vector


I have a tibble called df:

> class(df)
[1] "tbl_df"     "tbl"        "data.frame"

Now I run:

> sen <- df[df$my_dummy==0, "col_name"]

This returns another tibble:

> class(sen)
[1] "tbl_df"     "tbl"        "data.frame"

Why?

How can I get a "numeric" out of it?


Solution

  • try pull

    sen <- df %>%
      filter(my_dummy == 0) %>%
      pull(col_name)