More work on O'Reilly book
* Make width narrower * Convert deps to table * Strip chapter status
This commit is contained in:
@@ -1,13 +1,5 @@
|
||||
<section data-type="chapter" id="chp-logicals">
|
||||
<h1><span id="sec-logicals" class="quarto-section-identifier d-none d-lg-block"><span class="chapter-title">Logical vectors</span></span></h1><div data-type="note"><div class="callout-body d-flex">
|
||||
<div class="callout-icon-container">
|
||||
<i class="callout-icon"/>
|
||||
</div>
|
||||
|
||||
</div>
|
||||
|
||||
<p>You are reading the work-in-progress second edition of R for Data Science. This chapter should be readable but is currently undergoing final polishing. You can find the complete first edition at <a href="https://r4ds.had.co.nz" class="uri">https://r4ds.had.co.nz</a>.</p></div>
|
||||
|
||||
<h1><span id="sec-logicals" class="quarto-section-identifier d-none d-lg-block"><span class="chapter-title">Logical vectors</span></span></h1><p>::: status callout-note You are reading the work-in-progress second edition of R for Data Science. This chapter should be readable but is currently undergoing final polishing. You can find the complete first edition at <a href="https://r4ds.had.co.nz" class="uri">https://r4ds.had.co.nz</a>. :::</p>
|
||||
<section id="introduction" data-type="sect1">
|
||||
<h1>
|
||||
Introduction</h1>
|
||||
@@ -55,14 +47,14 @@ Comparisons</h1>
|
||||
<pre data-type="programlisting" data-code-language="downlit">flights |>
|
||||
filter(dep_time > 600 & dep_time < 2000 & abs(arr_delay) < 20)
|
||||
#> # A tibble: 172,286 × 19
|
||||
#> year month day dep_time sched_dep…¹ dep_d…² arr_t…³ sched…⁴ arr_d…⁵ carrier
|
||||
#> <int> <int> <int> <int> <int> <dbl> <int> <int> <dbl> <chr>
|
||||
#> 1 2013 1 1 601 600 1 844 850 -6 B6
|
||||
#> 2 2013 1 1 602 610 -8 812 820 -8 DL
|
||||
#> 3 2013 1 1 602 605 -3 821 805 16 MQ
|
||||
#> 4 2013 1 1 606 610 -4 858 910 -12 AA
|
||||
#> 5 2013 1 1 606 610 -4 837 845 -8 DL
|
||||
#> 6 2013 1 1 607 607 0 858 915 -17 UA
|
||||
#> year month day dep_time sched_…¹ dep_d…² arr_t…³ sched…⁴ arr_d…⁵ carrier
|
||||
#> <int> <int> <int> <int> <int> <dbl> <int> <int> <dbl> <chr>
|
||||
#> 1 2013 1 1 601 600 1 844 850 -6 B6
|
||||
#> 2 2013 1 1 602 610 -8 812 820 -8 DL
|
||||
#> 3 2013 1 1 602 605 -3 821 805 16 MQ
|
||||
#> 4 2013 1 1 606 610 -4 858 910 -12 AA
|
||||
#> 5 2013 1 1 606 610 -4 837 845 -8 DL
|
||||
#> 6 2013 1 1 607 607 0 858 915 -17 UA
|
||||
#> # … with 172,280 more rows, 9 more variables: flight <int>, tailnum <chr>,
|
||||
#> # origin <chr>, dest <chr>, air_time <dbl>, distance <dbl>, hour <dbl>,
|
||||
#> # minute <dbl>, time_hour <dttm>, and abbreviated variable names
|
||||
@@ -185,14 +177,14 @@ is.na(c("a", NA, "b"))
|
||||
<pre data-type="programlisting" data-code-language="downlit">flights |>
|
||||
filter(is.na(dep_time))
|
||||
#> # A tibble: 8,255 × 19
|
||||
#> year month day dep_time sched_dep…¹ dep_d…² arr_t…³ sched…⁴ arr_d…⁵ carrier
|
||||
#> <int> <int> <int> <int> <int> <dbl> <int> <int> <dbl> <chr>
|
||||
#> 1 2013 1 1 NA 1630 NA NA 1815 NA EV
|
||||
#> 2 2013 1 1 NA 1935 NA NA 2240 NA AA
|
||||
#> 3 2013 1 1 NA 1500 NA NA 1825 NA AA
|
||||
#> 4 2013 1 1 NA 600 NA NA 901 NA B6
|
||||
#> 5 2013 1 2 NA 1540 NA NA 1747 NA EV
|
||||
#> 6 2013 1 2 NA 1620 NA NA 1746 NA EV
|
||||
#> year month day dep_time sched_…¹ dep_d…² arr_t…³ sched…⁴ arr_d…⁵ carrier
|
||||
#> <int> <int> <int> <int> <int> <dbl> <int> <int> <dbl> <chr>
|
||||
#> 1 2013 1 1 NA 1630 NA NA 1815 NA EV
|
||||
#> 2 2013 1 1 NA 1935 NA NA 2240 NA AA
|
||||
#> 3 2013 1 1 NA 1500 NA NA 1825 NA AA
|
||||
#> 4 2013 1 1 NA 600 NA NA 901 NA B6
|
||||
#> 5 2013 1 2 NA 1540 NA NA 1747 NA EV
|
||||
#> 6 2013 1 2 NA 1620 NA NA 1746 NA EV
|
||||
#> # … with 8,249 more rows, 9 more variables: flight <int>, tailnum <chr>,
|
||||
#> # origin <chr>, dest <chr>, air_time <dbl>, distance <dbl>, hour <dbl>,
|
||||
#> # minute <dbl>, time_hour <dttm>, and abbreviated variable names
|
||||
@@ -204,14 +196,14 @@ is.na(c("a", NA, "b"))
|
||||
filter(month == 1, day == 1) |>
|
||||
arrange(dep_time)
|
||||
#> # A tibble: 842 × 19
|
||||
#> year month day dep_time sched_dep…¹ dep_d…² arr_t…³ sched…⁴ arr_d…⁵ carrier
|
||||
#> <int> <int> <int> <int> <int> <dbl> <int> <int> <dbl> <chr>
|
||||
#> 1 2013 1 1 517 515 2 830 819 11 UA
|
||||
#> 2 2013 1 1 533 529 4 850 830 20 UA
|
||||
#> 3 2013 1 1 542 540 2 923 850 33 AA
|
||||
#> 4 2013 1 1 544 545 -1 1004 1022 -18 B6
|
||||
#> 5 2013 1 1 554 600 -6 812 837 -25 DL
|
||||
#> 6 2013 1 1 554 558 -4 740 728 12 UA
|
||||
#> year month day dep_time sched_…¹ dep_d…² arr_t…³ sched…⁴ arr_d…⁵ carrier
|
||||
#> <int> <int> <int> <int> <int> <dbl> <int> <int> <dbl> <chr>
|
||||
#> 1 2013 1 1 517 515 2 830 819 11 UA
|
||||
#> 2 2013 1 1 533 529 4 850 830 20 UA
|
||||
#> 3 2013 1 1 542 540 2 923 850 33 AA
|
||||
#> 4 2013 1 1 544 545 -1 1004 1022 -18 B6
|
||||
#> 5 2013 1 1 554 600 -6 812 837 -25 DL
|
||||
#> 6 2013 1 1 554 558 -4 740 728 12 UA
|
||||
#> # … with 836 more rows, 9 more variables: flight <int>, tailnum <chr>,
|
||||
#> # origin <chr>, dest <chr>, air_time <dbl>, distance <dbl>, hour <dbl>,
|
||||
#> # minute <dbl>, time_hour <dttm>, and abbreviated variable names
|
||||
@@ -221,14 +213,14 @@ flights |>
|
||||
filter(month == 1, day == 1) |>
|
||||
arrange(desc(is.na(dep_time)), dep_time)
|
||||
#> # A tibble: 842 × 19
|
||||
#> year month day dep_time sched_dep…¹ dep_d…² arr_t…³ sched…⁴ arr_d…⁵ carrier
|
||||
#> <int> <int> <int> <int> <int> <dbl> <int> <int> <dbl> <chr>
|
||||
#> 1 2013 1 1 NA 1630 NA NA 1815 NA EV
|
||||
#> 2 2013 1 1 NA 1935 NA NA 2240 NA AA
|
||||
#> 3 2013 1 1 NA 1500 NA NA 1825 NA AA
|
||||
#> 4 2013 1 1 NA 600 NA NA 901 NA B6
|
||||
#> 5 2013 1 1 517 515 2 830 819 11 UA
|
||||
#> 6 2013 1 1 533 529 4 850 830 20 UA
|
||||
#> year month day dep_time sched_…¹ dep_d…² arr_t…³ sched…⁴ arr_d…⁵ carrier
|
||||
#> <int> <int> <int> <int> <int> <dbl> <int> <int> <dbl> <chr>
|
||||
#> 1 2013 1 1 NA 1630 NA NA 1815 NA EV
|
||||
#> 2 2013 1 1 NA 1935 NA NA 2240 NA AA
|
||||
#> 3 2013 1 1 NA 1500 NA NA 1825 NA AA
|
||||
#> 4 2013 1 1 NA 600 NA NA 901 NA B6
|
||||
#> 5 2013 1 1 517 515 2 830 819 11 UA
|
||||
#> 6 2013 1 1 533 529 4 850 830 20 UA
|
||||
#> # … with 836 more rows, 9 more variables: flight <int>, tailnum <chr>,
|
||||
#> # origin <chr>, dest <chr>, air_time <dbl>, distance <dbl>, hour <dbl>,
|
||||
#> # minute <dbl>, time_hour <dttm>, and abbreviated variable names
|
||||
@@ -294,14 +286,14 @@ Order of operations</h2>
|
||||
<pre data-type="programlisting" data-code-language="downlit">flights |>
|
||||
filter(month == 11 | 12)
|
||||
#> # A tibble: 336,776 × 19
|
||||
#> year month day dep_time sched_dep…¹ dep_d…² arr_t…³ sched…⁴ arr_d…⁵ carrier
|
||||
#> <int> <int> <int> <int> <int> <dbl> <int> <int> <dbl> <chr>
|
||||
#> 1 2013 1 1 517 515 2 830 819 11 UA
|
||||
#> 2 2013 1 1 533 529 4 850 830 20 UA
|
||||
#> 3 2013 1 1 542 540 2 923 850 33 AA
|
||||
#> 4 2013 1 1 544 545 -1 1004 1022 -18 B6
|
||||
#> 5 2013 1 1 554 600 -6 812 837 -25 DL
|
||||
#> 6 2013 1 1 554 558 -4 740 728 12 UA
|
||||
#> year month day dep_time sched_…¹ dep_d…² arr_t…³ sched…⁴ arr_d…⁵ carrier
|
||||
#> <int> <int> <int> <int> <int> <dbl> <int> <int> <dbl> <chr>
|
||||
#> 1 2013 1 1 517 515 2 830 819 11 UA
|
||||
#> 2 2013 1 1 533 529 4 850 830 20 UA
|
||||
#> 3 2013 1 1 542 540 2 923 850 33 AA
|
||||
#> 4 2013 1 1 544 545 -1 1004 1022 -18 B6
|
||||
#> 5 2013 1 1 554 600 -6 812 837 -25 DL
|
||||
#> 6 2013 1 1 554 558 -4 740 728 12 UA
|
||||
#> # … with 336,770 more rows, 9 more variables: flight <int>, tailnum <chr>,
|
||||
#> # origin <chr>, dest <chr>, air_time <dbl>, distance <dbl>, hour <dbl>,
|
||||
#> # minute <dbl>, time_hour <dttm>, and abbreviated variable names
|
||||
@@ -356,14 +348,14 @@ c(1, 2, NA) %in% NA
|
||||
<pre data-type="programlisting" data-code-language="downlit">flights |>
|
||||
filter(dep_time %in% c(NA, 0800))
|
||||
#> # A tibble: 8,803 × 19
|
||||
#> year month day dep_time sched_dep…¹ dep_d…² arr_t…³ sched…⁴ arr_d…⁵ carrier
|
||||
#> <int> <int> <int> <int> <int> <dbl> <int> <int> <dbl> <chr>
|
||||
#> 1 2013 1 1 800 800 0 1022 1014 8 DL
|
||||
#> 2 2013 1 1 800 810 -10 949 955 -6 MQ
|
||||
#> 3 2013 1 1 NA 1630 NA NA 1815 NA EV
|
||||
#> 4 2013 1 1 NA 1935 NA NA 2240 NA AA
|
||||
#> 5 2013 1 1 NA 1500 NA NA 1825 NA AA
|
||||
#> 6 2013 1 1 NA 600 NA NA 901 NA B6
|
||||
#> year month day dep_time sched_…¹ dep_d…² arr_t…³ sched…⁴ arr_d…⁵ carrier
|
||||
#> <int> <int> <int> <int> <int> <dbl> <int> <int> <dbl> <chr>
|
||||
#> 1 2013 1 1 800 800 0 1022 1014 8 DL
|
||||
#> 2 2013 1 1 800 810 -10 949 955 -6 MQ
|
||||
#> 3 2013 1 1 NA 1630 NA NA 1815 NA EV
|
||||
#> 4 2013 1 1 NA 1935 NA NA 2240 NA AA
|
||||
#> 5 2013 1 1 NA 1500 NA NA 1825 NA AA
|
||||
#> 6 2013 1 1 NA 600 NA NA 901 NA B6
|
||||
#> # … with 8,797 more rows, 9 more variables: flight <int>, tailnum <chr>,
|
||||
#> # origin <chr>, dest <chr>, air_time <dbl>, distance <dbl>, hour <dbl>,
|
||||
#> # minute <dbl>, time_hour <dttm>, and abbreviated variable names
|
||||
|
||||
Reference in New Issue
Block a user