Select unique values with 'select' function in 'dplyr' library

后端 未结 3 855
野的像风
野的像风 2021-01-30 10:08

Is it possible to select all unique values from a column of a data.frame using select function in dplyr library? Something like \

3条回答
  •  南笙
    南笙 (楼主)
    2021-01-30 11:11

    Just to add to the other answers, if you would prefer to return a vector rather than a dataframe, you have the following options:

    dplyr < 0.7.0

    Enclose the dplyr functions in a parentheses and combine it with $ syntax:

    (mtcars %>% distinct(cyl))$cyl
    

    dplyr >= 0.7.0

    Use the pull verb:

    mtcars %>% distinct(cyl) %>% pull()
    

提交回复
热议问题