Skip to content

Commit

Permalink
select non existing columns
Browse files Browse the repository at this point in the history
  • Loading branch information
b-rodrigues committed Mar 20, 2020
1 parent d058474 commit 6e2fee1
Show file tree
Hide file tree
Showing 127 changed files with 1,881 additions and 1,725 deletions.
40 changes: 40 additions & 0 deletions 04-descriptives.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -1564,6 +1564,46 @@ gasoline %>%
select(starts_with("l"))
```
Another very neat trick is selecting columns that may or may not exist in your data frame. For this quick examples
let's use the `mtcars` dataset:
```{r}
sort(colnames(mtcars))
```
Let's create a vector with some column names:
```{r}
cols_to_select <- c("mpg", "cyl", "am", "nonsense")
```
The following selects the columns that exist
in the data frame but shows a warning for the column that does not exist:
```{r}
mtcars %>%
select(one_of(cols_to_select))
```
If you don't want a warning to show, use `any_of()` insetad:
```{r}
mtcars %>%
select(any_of(cols_to_select))
```
and finally, if you want it to fail, don't use any helper:
```{r, eval = FALSE}
mtcars %>%
select(cols_to_select)
```
```
Error: Can't subset columns that don't exist.
The column `nonsense` doesn't exist.
```
Bulk-renaming can be achieved using `rename_with()`
```{r}
Expand Down
Binary file modified _bookdown_files/modern_R_files/figure-html/unnamed-chunk-328-1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified _bookdown_files/modern_R_files/figure-html/unnamed-chunk-329-1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified _bookdown_files/modern_R_files/figure-html/unnamed-chunk-406-1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified _bookdown_files/modern_R_files/figure-html/unnamed-chunk-438-1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified _bookdown_files/modern_R_files/figure-html/unnamed-chunk-451-1.png
Binary file modified _bookdown_files/modern_R_files/figure-html/unnamed-chunk-458-1.png
1,415 changes: 714 additions & 701 deletions docs/defining-your-own-functions.html

Large diffs are not rendered by default.

764 changes: 428 additions & 336 deletions docs/descriptive-statistics-and-data-manipulation.html

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion docs/further-topics.html
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
<meta name="author" content="Bruno Rodrigues" />


<meta name="date" content="2020-03-18" />
<meta name="date" content="2020-03-20" />

<meta name="viewport" content="width=device-width, initial-scale=1" />
<meta name="apple-mobile-web-app-capable" content="yes" />
Expand Down
2 changes: 1 addition & 1 deletion docs/getting-to-know-rstudio.html
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
<meta name="author" content="Bruno Rodrigues" />


<meta name="date" content="2020-03-18" />
<meta name="date" content="2020-03-20" />

<meta name="viewport" content="width=device-width, initial-scale=1" />
<meta name="apple-mobile-web-app-capable" content="yes" />
Expand Down
540 changes: 270 additions & 270 deletions docs/graphs.html

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions docs/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
<meta name="author" content="Bruno Rodrigues" />


<meta name="date" content="2020-03-18" />
<meta name="date" content="2020-03-20" />

<meta name="viewport" content="width=device-width, initial-scale=1" />
<meta name="apple-mobile-web-app-capable" content="yes" />
Expand Down Expand Up @@ -376,7 +376,7 @@ <h1>
<div id="header">
<h1 class="title">Modern R with the tidyverse</h1>
<p class="author"><em>Bruno Rodrigues</em></p>
<p class="date"><em>2020-03-18</em></p>
<p class="date"><em>2020-03-20</em></p>
</div>
<div id="preface" class="section level1 unnumbered">
<h1>Preface</h1>
Expand Down
Binary file modified docs/modern_R_files/figure-html/unnamed-chunk-328-1.png
Binary file modified docs/modern_R_files/figure-html/unnamed-chunk-329-1.png
Binary file modified docs/modern_R_files/figure-html/unnamed-chunk-406-1.png
Binary file modified docs/modern_R_files/figure-html/unnamed-chunk-416-1.png
Binary file modified docs/modern_R_files/figure-html/unnamed-chunk-417-1.png
Binary file modified docs/modern_R_files/figure-html/unnamed-chunk-418-1.png
Binary file modified docs/modern_R_files/figure-html/unnamed-chunk-419-1.png
Binary file modified docs/modern_R_files/figure-html/unnamed-chunk-420-1.png
Binary file modified docs/modern_R_files/figure-html/unnamed-chunk-421-1.png
Binary file modified docs/modern_R_files/figure-html/unnamed-chunk-423-1.png
Binary file modified docs/modern_R_files/figure-html/unnamed-chunk-424-1.png
Binary file modified docs/modern_R_files/figure-html/unnamed-chunk-425-1.png
Binary file modified docs/modern_R_files/figure-html/unnamed-chunk-426-1.png
Binary file modified docs/modern_R_files/figure-html/unnamed-chunk-427-1.png
Binary file modified docs/modern_R_files/figure-html/unnamed-chunk-428-1.png
Binary file modified docs/modern_R_files/figure-html/unnamed-chunk-429-1.png
Binary file modified docs/modern_R_files/figure-html/unnamed-chunk-430-1.png
Binary file modified docs/modern_R_files/figure-html/unnamed-chunk-433-1.png
Binary file modified docs/modern_R_files/figure-html/unnamed-chunk-436-1.png
Binary file modified docs/modern_R_files/figure-html/unnamed-chunk-437-1.png
Binary file modified docs/modern_R_files/figure-html/unnamed-chunk-438-1.png
Binary file modified docs/modern_R_files/figure-html/unnamed-chunk-439-1.png
Binary file modified docs/modern_R_files/figure-html/unnamed-chunk-440-1.png
Binary file modified docs/modern_R_files/figure-html/unnamed-chunk-441-1.png
Binary file modified docs/modern_R_files/figure-html/unnamed-chunk-442-1.png
Binary file modified docs/modern_R_files/figure-html/unnamed-chunk-443-1.png
Binary file modified docs/modern_R_files/figure-html/unnamed-chunk-444-1.png
Binary file modified docs/modern_R_files/figure-html/unnamed-chunk-445-1.png
Binary file modified docs/modern_R_files/figure-html/unnamed-chunk-446-1.png
Binary file modified docs/modern_R_files/figure-html/unnamed-chunk-447-1.png
Binary file modified docs/modern_R_files/figure-html/unnamed-chunk-448-1.png
Binary file modified docs/modern_R_files/figure-html/unnamed-chunk-449-1.png
Binary file modified docs/modern_R_files/figure-html/unnamed-chunk-450-1.png
Binary file modified docs/modern_R_files/figure-html/unnamed-chunk-451-1.png
Binary file modified docs/modern_R_files/figure-html/unnamed-chunk-452-1.png
Binary file modified docs/modern_R_files/figure-html/unnamed-chunk-453-1.png
Binary file modified docs/modern_R_files/figure-html/unnamed-chunk-454-1.png
Binary file modified docs/modern_R_files/figure-html/unnamed-chunk-455-1.png
Binary file modified docs/modern_R_files/figure-html/unnamed-chunk-456-1.png
Binary file modified docs/modern_R_files/figure-html/unnamed-chunk-457-1.png
Binary file modified docs/modern_R_files/figure-html/unnamed-chunk-458-1.png
Binary file modified docs/modern_R_files/figure-html/unnamed-chunk-460-1.png
Binary file modified docs/modern_R_files/figure-html/unnamed-chunk-461-1.png
Binary file modified docs/modern_R_files/figure-html/unnamed-chunk-462-1.png
Binary file modified docs/modern_R_files/figure-html/unnamed-chunk-483-1.png
Binary file modified docs/modern_R_files/figure-html/unnamed-chunk-488-1.png
Binary file modified docs/modern_R_files/figure-html/unnamed-chunk-494-1.png
Binary file modified docs/modern_R_files/figure-html/unnamed-chunk-496-1.png
Binary file modified docs/modern_R_files/figure-html/unnamed-chunk-501-1.png
Binary file modified docs/modern_R_files/figure-html/unnamed-chunk-504-1.png
Binary file modified docs/modern_R_files/figure-html/unnamed-chunk-509-1.png
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
<meta name="author" content="Bruno Rodrigues" />


<meta name="date" content="2020-03-18" />
<meta name="date" content="2020-03-20" />

<meta name="viewport" content="width=device-width, initial-scale=1" />
<meta name="apple-mobile-web-app-capable" content="yes" />
Expand Down
266 changes: 133 additions & 133 deletions docs/package-development.html

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion docs/reading-and-writing-data.html
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
<meta name="author" content="Bruno Rodrigues" />


<meta name="date" content="2020-03-18" />
<meta name="date" content="2020-03-20" />

<meta name="viewport" content="width=device-width, initial-scale=1" />
<meta name="apple-mobile-web-app-capable" content="yes" />
Expand Down
2 changes: 1 addition & 1 deletion docs/references.html
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
<meta name="author" content="Bruno Rodrigues" />


<meta name="date" content="2020-03-18" />
<meta name="date" content="2020-03-20" />

<meta name="viewport" content="width=device-width, initial-scale=1" />
<meta name="apple-mobile-web-app-capable" content="yes" />
Expand Down
8 changes: 4 additions & 4 deletions docs/search_index.json

Large diffs are not rendered by default.

559 changes: 285 additions & 274 deletions docs/statistical-models.html

Large diffs are not rendered by default.

0 comments on commit 6e2fee1

Please sign in to comment.