Filtering and Selecting

Load Libraries

Here we load some libraries.

Lorem ipsum lorem ipsum dolor sit amen. Lorem ipsum lorem ipsum dolor sit amen. Lorem ipsum lorem ipsum dolor sit amen. Lorem ipsum lorem ipsum dolor sit amen.

library(tidyverse)
library(knitr)
library(highcharter)
library(plotly)

## print methods. SHould move out to optional script that is called based on parameter value
knit_print_reactable_5_rows <- function(df, options) {
  df[1:5,] %>% 
    reactable::reactable() %>% 
    knitr::knit_print()
}
# registerS3method("knit_print_reactable_5_rows", "data.frame", knit_print_reactable_5_rows)

## functions
source(here::here("chapter_04_data_wrangling/utils/functions.R"))

## autograders
suppressMessages(source(here::here("chapter_04_data_wrangling/lessons/01_filtering_and_selecting_autograder.R")))

question_icon <- fontawesome::fa("fas fa-robot", fill = "purple")

cars_head <- head(cars, 5)

Normal print table

cars
##    speed dist
## 1      4    2
## 2      4   10
## 3      7    4
## 4      7   22
## 5      8   16
## 6      9   10
## 7     10   18
## 8     10   26
## 9     10   34
## 10    11   17
## 11    11   28
## 12    12   14
## 13    12   20
## 14    12   24
## 15    12   28
## 16    13   26
## 17    13   34
## 18    13   34
## 19    13   46
## 20    14   26
## 21    14   36
## 22    14   60
## 23    14   80
## 24    15   20
## 25    15   26
## 26    15   54
## 27    16   32
## 28    16   40
## 29    17   32
## 30    17   40
## 31    17   50
## 32    18   42
## 33    18   56
## 34    18   76
## 35    18   84
## 36    19   36
## 37    19   46
## 38    19   68
## 39    20   32
## 40    20   48
## 41    20   52
## 42    20   56
## 43    20   64
## 44    22   66
## 45    23   54
## 46    24   70
## 47    24   92
## 48    24   93
## 49    24  120
## 50    25   85

5 rows print table

cars
##    speed dist
## 1      4    2
## 2      4   10
## 3      7    4
## 4      7   22
## 5      8   16
## 6      9   10
## 7     10   18
## 8     10   26
## 9     10   34
## 10    11   17
## 11    11   28
## 12    12   14
## 13    12   20
## 14    12   24
## 15    12   28
## 16    13   26
## 17    13   34
## 18    13   34
## 19    13   46
## 20    14   26
## 21    14   36
## 22    14   60
## 23    14   80
## 24    15   20
## 25    15   26
## 26    15   54
## 27    16   32
## 28    16   40
## 29    17   32
## 30    17   40
## 31    17   50
## 32    18   42
## 33    18   56
## 34    18   76
## 35    18   84
## 36    19   36
## 37    19   46
## 38    19   68
## 39    20   32
## 40    20   48
## 41    20   52
## 42    20   56
## 43    20   64
## 44    22   66
## 45    23   54
## 46    24   70
## 47    24   92
## 48    24   93
## 49    24  120
## 50    25   85

df print table

cars
##    speed dist
## 1      4    2
## 2      4   10
## 3      7    4
## 4      7   22
## 5      8   16
## 6      9   10
## 7     10   18
## 8     10   26
## 9     10   34
## 10    11   17
## 11    11   28
## 12    12   14
## 13    12   20
## 14    12   24
## 15    12   28
## 16    13   26
## 17    13   34
## 18    13   34
## 19    13   46
## 20    14   26
## 21    14   36
## 22    14   60
## 23    14   80
## 24    15   20
## 25    15   26
## 26    15   54
## 27    16   32
## 28    16   40
## 29    17   32
## 30    17   40
## 31    17   50
## 32    18   42
## 33    18   56
## 34    18   76
## 35    18   84
## 36    19   36
## 37    19   46
## 38    19   68
## 39    20   32
## 40    20   48
## 41    20   52
## 42    20   56
## 43    20   64
## 44    22   66
## 45    23   54
## 46    24   70
## 47    24   92
## 48    24   93
## 49    24  120
## 50    25   85

plot

plot(cars)

leaflet

library(leaflet)

Abuja <-
  leaflet(options = leafletOptions(minZoom = 11, maxZoom = 15)) %>%
  setMaxBounds(lng1 = 7.379379, lat1 = 9.122775, lng2 = 7.564087, lat2 = 9.001400) %>%
  addTiles() %>%
  addMarkers(lng =7.491302, lat = 9.072264, popup = "hello!") %>%
  setView(lng = 7.491302, lat = 9.072264, zoom = 12)

Abuja

plotly

library(plotly)

p <- ggplot(cars, aes(speed, dist)) + geom_point()

ggplotly(p)

highcharter

cars$speed %>% highcharter::hchart()

reactable

cars_head %>% reactable::reactable()

DT

DT::datatable(cars_head)





Practice Question 5

## Test

Quiz

How many columns in the dataset starts with “is? (Use select)

Related Articles