library(tidyverse)
  1. Read in the UFO dataset (used in the Data IO lectures) as an R object called ufo. You can read directly from the web here: https://raw.githubusercontent.com/SISBID/Module1/gh-pages/data/ufo/ufo_data_complete.csv . You can ignore the “problems” with some rows.
library(readr)
ufo <- read_csv("https://raw.githubusercontent.com/SISBID/Module1/gh-pages/data/ufo/ufo_data_complete.csv")
## Warning: One or more parsing issues, call `problems()` on your data frame for details, e.g.:
##   dat <- vroom(...)
##   problems(dat)
## Rows: 88875 Columns: 11
## ── Column specification ──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────
## Delimiter: ","
## chr (10): datetime, city, state, country, shape, duration (hours/min), comme...
## dbl  (1): duration (seconds)
## 
## ℹ Use `spec()` to retrieve the full column specification for this data.
## ℹ Specify the column types or set `show_col_types = FALSE` to quiet this message.

Clean up the column/variable names of the ufo dataset to remove spaces and non-alphanumeric characters. You can use the dplyr::rename() function or use the janitor::clean_names() function.

library(janitor)
ufo <- clean_names(ufo)
  1. How might one check how many UFO sightings were reported on a time scale of hours, specifically using the duration (hours/min) originally-named column? For sake of ease, assume it is only coded as “hour” and no other way.
 ufo |> filter(str_detect(duration_hours_min, "hour"))
## # A tibble: 4,808 × 11
##    datetime        city  state country shape duration_seconds duration_hours_min
##    <chr>           <chr> <chr> <chr>   <chr>            <dbl> <chr>             
##  1 10/10/1956 21:… edna  tx    us      circ…               20 1/2 hour          
##  2 10/10/1974 23:… huds… ks    us      light             1200 one hour?         
##  3 10/10/1992 17:… pana… fl    us      form…             3600 1 hour(?)         
##  4 10/10/1994 15:… merc… tx    <NA>    cigar             3600 1 hour            
##  5 10/10/1994 23:… toro… on    ca      sphe…             3600 ~1 hour           
##  6 10/10/1997 16:… conn… in    us      delta            14400 4 hours           
##  7 10/10/1997 21:… aust… mn    us      other             3600 1-hour            
##  8 10/10/1998 22:… st. … nf    ca      egg               7200 2 hours           
##  9 10/10/1999 00:… mart… ca    us      chan…             3600 1 hour            
## 10 10/10/1999 11:… san … ca    us      fire…             3600 1 hour            
## # ℹ 4,798 more rows
## # ℹ 4 more variables: comments <chr>, date_posted <chr>, latitude <chr>,
## #   longitude <chr>
  1. How many of the minutes-scale observations (assuming “min” is the pattern to look for) have durations greater than 14400 seconds (or 4 hours)?
sub <- ufo |> filter(str_detect(duration_hours_min, "min"),
                      duration_seconds >14400)
nrow(sub)
## [1] 10
  1. How many ufo sighting cities end in “port”? (hint - remember stringr uses vectors or variables)
ufo |> pull(city) |> str_subset("port$") |> length() # C
## [1] 497