O'Reilly logo

Data Analysis with R - Second Edition by Tony Fischetti

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Selecting and renaming columns

The primary way to select columns in dplyr is by using the select function. At its simplest, select just takes the tibble (or data.table or data.frame, and so on) to operate on and an arbitrary number of columns. But, as we’ll see, select has a few tricks up its sleeve and is far more powerful than it seems, as shown in the following code:

> # select trackname and artist> tracks %>% select(trackname, artist)# A tibble: 138,135 x 2   trackname                                artist   <chr>                                    <chr>  1 A Perfect Match                          A*Teens 2 Mamma Mia                                A*Teens 3 Upside Down                              A*Teens…# ... with 138,125 more rows>> # same thing using the standard-evaluation version> tracks %>% select_(“trackname”, “artist”)# A tibble: 138,135 x 2   trackname                                artist   <chr>                                    <chr>  1 A Perfect ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required