Skip to contents

A function between dplyr's transmute and mutate

Usage

transmutate(.data, ...)

Source

https://stackoverflow.com/questions/51428156/dplyr-mutate-transmute-drop-only-the-columns-used-in-the-formula

Arguments

.data

Data frame to pass to the function

...

Variables to pass to the function

Value

Data frame with mutated variables and none of the variables used in the mutations, but, unlike dplyr::transmute(), all other unnamed variables.

Examples

# \donttest{
pluck(emperors, "wikipedia")
#> # A tibble: 68 × 15
#>    ID       Begin End   FullName Birth Death CityBirth ProvinceBirth Rise  Cause
#>    <chr>    <mda> <mda> <chr>    <chr> <chr> <chr>     <chr>         <chr> <chr>
#>  1 Augustus -002… 0014… IMPERAT… 0062… 0014… Rome      Italia        Birt… Assa…
#>  2 Tiberius 0014… 0037… TIBERIV… 0041… 0037… Rome      Italia        Birt… Assa…
#>  3 Caligula 0037… 0041… GAIVS I… 0012… 0041… Antitum   Italia        Birt… Assa…
#>  4 Claudius 0041… 0054… TIBERIV… 0009… 0054… Lugdunum  Gallia Lugdu… Birt… Assa…
#>  5 Nero     0054… 0068… NERO CL… 0037… 0068… Antitum   Italia        Birt… Suic…
#>  6 Galba    0068… 0069… SERVIVS… 0002… 0069… Terracina Italia        Seiz… Assa…
#>  7 Otho     0069… 0069… MARCVS … 0032… 0069… Terentin… Italia        Appo… Suic…
#>  8 Vitelli… 0069… 0069… AVLVS V… 0015… 0069… Rome      Italia        Seiz… Assa…
#>  9 Vespasi… 0069… 0079… TITVS F… 0009… 0079… Falacrine Italia        Seiz… Natu…
#> 10 Titus    0079… 0081… TITVS F… 0039… 0081… Rome      Italia        Birt… Natu…
#> # ℹ 58 more rows
#> # ℹ 5 more variables: Killer <chr>, Dynasty <chr>, Era <chr>, Notes <chr>,
#> #   Verif <chr>
transmutate(emperors$wikipedia, Beginning = Begin)
#> # A tibble: 68 × 15
#>    ID      End   FullName Birth Death CityBirth ProvinceBirth Rise  Cause Killer
#>    <chr>   <mda> <chr>    <chr> <chr> <chr>     <chr>         <chr> <chr> <chr> 
#>  1 August… 0014… IMPERAT… 0062… 0014… Rome      Italia        Birt… Assa… Wife  
#>  2 Tiberi… 0037… TIBERIV… 0041… 0037… Rome      Italia        Birt… Assa… Other…
#>  3 Caligu… 0041… GAIVS I… 0012… 0041… Antitum   Italia        Birt… Assa… Senate
#>  4 Claudi… 0054… TIBERIV… 0009… 0054… Lugdunum  Gallia Lugdu… Birt… Assa… Wife  
#>  5 Nero    0068… NERO CL… 0037… 0068… Antitum   Italia        Birt… Suic… Senate
#>  6 Galba   0069… SERVIVS… 0002… 0069… Terracina Italia        Seiz… Assa… Other…
#>  7 Otho    0069… MARCVS … 0032… 0069… Terentin… Italia        Appo… Suic… Other…
#>  8 Vitell… 0069… AVLVS V… 0015… 0069… Rome      Italia        Seiz… Assa… Other…
#>  9 Vespas… 0079… TITVS F… 0009… 0079… Falacrine Italia        Seiz… Natu… Disea…
#> 10 Titus   0081… TITVS F… 0039… 0081… Rome      Italia        Birt… Natu… Disea…
#> # ℹ 58 more rows
#> # ℹ 5 more variables: Dynasty <chr>, Era <chr>, Notes <chr>, Verif <chr>,
#> #   Beginning <mdate>
# }