How does dplyr's select helper function everything() differ from copying?

后端 未结 2 1133
萌比男神i
萌比男神i 2020-12-31 18:11

What is the use case for

select(iris, everything())

as opposed to e.g. just copying the data.frame?

2条回答
  •  再見小時候
    2020-12-31 18:26

    Looking for references to everything in ?select, they have an example use for reordering columns:

    # Reorder variables: keep the variable "Species" in the front
    select(iris, Species, everything())
    

    In this case the Species column is moved to the first column, all columns are kept, and no columns are duplicated.

    Select helpers are used for more than just the select function - for example, in dplyr version 1.0 and greater, you may want to use it in across() to mutate or summarize all columns.

    Since this question was asked, the select helpers have been broken out into their own package, tidyselect. The tidyselect page on CRAN has a lengthy list of reverse imports - it's likely that many of the packages importing tidyselect have cases where everything() is useful.

提交回复
热议问题