In this lab you can use the interactive console to explore but please record your commands here. Remember anything you type here can be “sent” to the console with Cmd-Enter (OS-X) or Cntr-Enter (Windows/Linux) (But only in side the {r} areas).

library(tidyverse)
  1. Read in a slice of the “ufo” dataset from “https://sisbid.github.io/Data-Wrangling/data/ufo/ufo_slice_5.csv” using read_csv, call it ufo_slice_5.
ufo_slice_5 <- read_csv("https://sisbid.github.io/Data-Wrangling/data/ufo/ufo_slice_5.csv")
## Rows: 20 Columns: 11
## ── Column specification ──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────
## Delimiter: ","
## chr (8): datetime, city, state, country, shape, duration (hours/min), commen...
## dbl (3): duration (seconds), latitude, longitude
## 
## ℹ 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.
  1. Use a few functions to check out the data (e.g., head(), glimpse(), str() etc.). Do results look different if you had used read_delim above?
str(ufo_slice_5)
## spc_tbl_ [20 × 11] (S3: spec_tbl_df/tbl_df/tbl/data.frame)
##  $ datetime            : chr [1:20] "8/2/2012 21:00" "10/6/1995 19:00" "4/17/2005 23:00" "12/31/2013 23:10" ...
##  $ city                : chr [1:20] "kennewick" "puyallup" "grovetown" "corvallis" ...
##  $ state               : chr [1:20] "wa" "wa" "ga" "or" ...
##  $ country             : chr [1:20] "us" "us" "us" "us" ...
##  $ shape               : chr [1:20] "triangle" NA "circle" "circle" ...
##  $ duration (seconds)  : num [1:20] 600 900 2700 60 1200 120 60 2 7200 1680 ...
##  $ duration (hours/min): chr [1:20] "5-10 minutes" "15 min." "45 minutes" "1 minute" ...
##  $ comments            : chr [1:20] "Saw three triangle shaped craft with red and white lights and moving in slow formation.." "Man witnesses &quot;small whitish&#44 blue-green ball&quot; pass overhead&#44 flying to east." "Object appeared to be a star at first glance sitting low on the horizon  ((NUFORC Note:  Possibly Sirius.  PD))" "2 amber lights dimming as ascending into sky.  Moving then stopping." ...
##  $ date posted         : chr [1:20] "8/19/2012" "11/2/1999" "5/11/2005" "1/10/2014" ...
##  $ latitude            : num [1:20] 46.2 47.2 33.5 44.6 33.4 ...
##  $ longitude           : num [1:20] -119.1 -122.3 -82.2 -123.3 -111.5 ...
##  - attr(*, "spec")=
##   .. cols(
##   ..   datetime = col_character(),
##   ..   city = col_character(),
##   ..   state = col_character(),
##   ..   country = col_character(),
##   ..   shape = col_character(),
##   ..   `duration (seconds)` = col_double(),
##   ..   `duration (hours/min)` = col_character(),
##   ..   comments = col_character(),
##   ..   `date posted` = col_character(),
##   ..   latitude = col_double(),
##   ..   longitude = col_double()
##   .. )
##  - attr(*, "problems")=<pointer: 0x6000022c2250>
head(ufo_slice_5)
## # A tibble: 6 × 11
##   datetime city  state country shape `duration (seconds)` `duration (hours/min)`
##   <chr>    <chr> <chr> <chr>   <chr>                <dbl> <chr>                 
## 1 8/2/201… kenn… wa    us      tria…                  600 5-10 minutes          
## 2 10/6/19… puya… wa    us      <NA>                   900 15 min.               
## 3 4/17/20… grov… ga    us      circ…                 2700 45 minutes            
## 4 12/31/2… corv… or    us      circ…                   60 1 minute              
## 5 3/30/20… apac… az    us      light                 1200 20 minutes            
## 6 6/22/20… pitt… nj    us      light                  120 a few minutes         
## # ℹ 4 more variables: comments <chr>, `date posted` <chr>, latitude <dbl>,
## #   longitude <dbl>
glimpse(ufo_slice_5)
## Rows: 20
## Columns: 11
## $ datetime               <chr> "8/2/2012 21:00", "10/6/1995 19:00", "4/17/2005…
## $ city                   <chr> "kennewick", "puyallup", "grovetown", "corvalli…
## $ state                  <chr> "wa", "wa", "ga", "or", "az", "nj", "tx", "ca",…
## $ country                <chr> "us", "us", "us", "us", "us", "us", NA, "us", "…
## $ shape                  <chr> "triangle", NA, "circle", "circle", "light", "l…
## $ `duration (seconds)`   <dbl> 600, 900, 2700, 60, 1200, 120, 60, 2, 7200, 168…
## $ `duration (hours/min)` <chr> "5-10 minutes", "15 min.", "45 minutes", "1 min…
## $ comments               <chr> "Saw three triangle shaped craft with red and w…
## $ `date posted`          <chr> "8/19/2012", "11/2/1999", "5/11/2005", "1/10/20…
## $ latitude               <dbl> 46.21139, 47.18556, 33.45028, 44.56472, 33.4150…
## $ longitude              <dbl> -119.13611, -122.29167, -82.19833, -123.26083, …
nrow(ufo_slice_5)
## [1] 20
  1. Repeat 1-2 for “https://sisbid.github.io/Data-Wrangling/data/ufo/ufo_slice_6.txt” using read_delim, call it ufo_slice_6. Should any additional arguments be used?
ufo_slice_6 <- read_delim("https://sisbid.github.io/Data-Wrangling/data/ufo/ufo_slice_6.txt")
## Rows: 20 Columns: 11
## ── Column specification ──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────
## Delimiter: ":"
## chr (8): datetime, city, state, country, shape, duration (hours/min), commen...
## dbl (3): duration (seconds), latitude, longitude
## 
## ℹ 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.
ufo_slice_6
## # A tibble: 20 × 11
##    datetime                city         state country shape `duration (seconds)`
##    <chr>                   <chr>        <chr> <chr>   <chr>                <dbl>
##  1 "      6/30/1973 24:00" "los alamos" nm    us      <NA>                     0
##  2 "5/16/2005 19:15"       "oklahoma c… ok    us      tria…                  480
##  3 "      9/24/2009 00:00" "cambridge"  nh    <NA>    form…                 1200
##  4 "6/15/1981 19:00"       "foxton (ne… <NA>  <NA>    oval                  1200
##  5 "  8/20/2013 03:00"     "springfiel… va    us      cigar                 3600
##  6 "11/16/2012 23:50"      "     alto"  mi    us      light                  120
##  7 "11/8/2007 23:30"       "aztec"      nm    us      fire…                 3600
##  8 "2/23/1996 21:29"       "madison"    tn    us      <NA>                    60
##  9 "3/3/2012 22:15"        "greensboro" nc    us      light                  900
## 10 "9/8/2005 05:43"        "gainesvill… ga    us      other                  120
## 11 "11/11/1978 18:00"      "st. albert… ab    ca      unkn…                 1200
## 12 "6/15/2006 21:45"       "tampa"      fl    us      light                   20
## 13 "7/13/2012 22:00"       "wapakoneta" oh    us      fire…                  120
## 14 "8/9/2008 22:50"        "buchholz (… <NA>  de      light                   60
## 15 "12/16/2012 18:25"      "bakersfiel… ca    us      light                  120
## 16 "7/21/2006 23:35"       "erie"       pa    us      light                   15
## 17 "12/8/2012 06:00"       "chetek"     wi    us      light                  900
## 18 "9/30/2011 21:50"       "searcy"     ar    us      diam…                  120
## 19 "8/7/2006 00:26"        "nanaimo (c… bc    ca      tria…                    0
## 20 "7/10/2009 23:00"       "bear creek" al    us      circ…                    4
## # ℹ 5 more variables: `duration (hours/min)` <chr>, comments <chr>,
## #   `date posted` <chr>, latitude <dbl>, longitude <dbl>
ufo_slice_6 <- read_delim("https://sisbid.github.io/Data-Wrangling/data/ufo/ufo_slice_6.txt", trim_ws = TRUE)
## Rows: 20 Columns: 11
## ── Column specification ──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────
## Delimiter: ":"
## chr (8): datetime, city, state, country, shape, duration (hours/min), commen...
## dbl (3): duration (seconds), latitude, longitude
## 
## ℹ 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.
ufo_slice_6
## # A tibble: 20 × 11
##    datetime         city                state country shape `duration (seconds)`
##    <chr>            <chr>               <chr> <chr>   <chr>                <dbl>
##  1 6/30/1973 24:00  los alamos          nm    us      <NA>                     0
##  2 5/16/2005 19:15  oklahoma city       ok    us      tria…                  480
##  3 9/24/2009 00:00  cambridge           nh    <NA>    form…                 1200
##  4 6/15/1981 19:00  foxton (new zealan… <NA>  <NA>    oval                  1200
##  5 8/20/2013 03:00  springfield         va    us      cigar                 3600
##  6 11/16/2012 23:50 alto                mi    us      light                  120
##  7 11/8/2007 23:30  aztec               nm    us      fire…                 3600
##  8 2/23/1996 21:29  madison             tn    us      <NA>                    60
##  9 3/3/2012 22:15   greensboro          nc    us      light                  900
## 10 9/8/2005 05:43   gainesville         ga    us      other                  120
## 11 11/11/1978 18:00 st. albert (canada) ab    ca      unkn…                 1200
## 12 6/15/2006 21:45  tampa               fl    us      light                   20
## 13 7/13/2012 22:00  wapakoneta          oh    us      fire…                  120
## 14 8/9/2008 22:50   buchholz (germany)  <NA>  de      light                   60
## 15 12/16/2012 18:25 bakersfield         ca    us      light                  120
## 16 7/21/2006 23:35  erie                pa    us      light                   15
## 17 12/8/2012 06:00  chetek              wi    us      light                  900
## 18 9/30/2011 21:50  searcy              ar    us      diam…                  120
## 19 8/7/2006 00:26   nanaimo (canada)    bc    ca      tria…                    0
## 20 7/10/2009 23:00  bear creek          al    us      circ…                    4
## # ℹ 5 more variables: `duration (hours/min)` <chr>, comments <chr>,
## #   `date posted` <chr>, latitude <dbl>, longitude <dbl>

Practice on your own

  1. Try using read_table and read_delim on “https://sisbid.github.io/Data-Wrangling/data/ufo/ufo_slice_7.txt”. Which one is more appropriate?
# read_delim! read_table interprets all whitespace as delimiting - spaces in our data interfere with this function reading the data.
ufo_slice_7_table <- read_table("https://sisbid.github.io/Data-Wrangling/data/ufo/ufo_slice_7.txt")
## Warning: Duplicated column names deduplicated: '"duration' => '"duration_1' [8]
## 
## ── Column specification ──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────
## cols(
##   datetime = col_character(),
##   city = col_character(),
##   state = col_character(),
##   country = col_character(),
##   shape = col_character(),
##   `"duration` = col_character(),
##   `(seconds)"` = col_character(),
##   `"duration_1` = col_character(),
##   `(hours/min)"` = col_character(),
##   comments = col_character(),
##   `"date` = col_character(),
##   `posted"` = col_character(),
##   latitude = col_character(),
##   longitude = col_character()
## )
## Warning: 20 parsing failures.
## row col   expected     actual                                                               file
##   1  -- 14 columns 25 columns 'https://sisbid.github.io/Data-Wrangling/data/ufo/ufo_slice_7.txt'
##   2  -- 14 columns 29 columns 'https://sisbid.github.io/Data-Wrangling/data/ufo/ufo_slice_7.txt'
##   3  -- 14 columns 19 columns 'https://sisbid.github.io/Data-Wrangling/data/ufo/ufo_slice_7.txt'
##   4  -- 14 columns 19 columns 'https://sisbid.github.io/Data-Wrangling/data/ufo/ufo_slice_7.txt'
##   5  -- 14 columns 21 columns 'https://sisbid.github.io/Data-Wrangling/data/ufo/ufo_slice_7.txt'
## ... ... .......... .......... ..................................................................
## See problems(...) for more details.
ufo_slice_7_delim <- read_delim("https://sisbid.github.io/Data-Wrangling/data/ufo/ufo_slice_7.txt")
## Rows: 20 Columns: 11
## ── Column specification ──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────
## Delimiter: " "
## chr (8): datetime, city, state, country, shape, duration (hours/min), commen...
## dbl (3): duration (seconds), latitude, longitude
## 
## ℹ 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.