Extract a dplyr tbl column as a vector

后端 未结 7 1281

Is there a more succinct way to get one column of a dplyr tbl as a vector, from a tbl with database back-end (i.e. the data frame/table can\'t be subset directly)?



        
相关标签:
7条回答
  • 2020-11-22 16:58

    If you are used to using square brackets for indexing, another option is to just to wrap the usual indexing approach in a call to deframe(), e.g.:

    library(tidyverse)
    
    iris2 <- as_tibble(iris)
    
    # using column name
    deframe(iris2[, 'Sepal.Length'])
    
    # [1] 5.1 4.9 4.7 4.6 5.0 5.4
    
    # using column number
    deframe(iris2[, 1])
    
    # [1] 5.1 4.9 4.7 4.6 5.0 5.4
    

    That and pull() are both pretty good ways of getting a tibble column.

    0 讨论(0)
提交回复
热议问题