Import Data to R

It is the first big hurdle when dealing with data in R.

You are most likely to have looked at, organised and examined your data files in Excel.

Opening data in R is fairly simply, but organising it for analysis might take some thought and consideration. You’ll guess that it is possible to use the File | Import Dataset menu option in RStudio to import your data (to learn more see Importing Data with RStudio), however we’re going to do it the proper way with a command.

R can import all types of data:

  • (Tab, Blank space) Delimited Text
  • CSV files
  • Excel files
  • JSON
  • SAS
  • STATA
  • MiniTab
  • SPSS…

In this section we will show you how to access the most commonly used data types. Once you start playing with the data and wrangling it in the way it suits you for your analytical manipulations you might find it interesting to explore the options for writing data. Here, we are not going to show you how to do it, but rather focus on basic read data functionality in R.

the R base

The simplest data form is a text file. Text files can be read by any computer operating system and by almost all different kinds of statistical programs. Saving data as a text file makes your data highly accessible. If you have a text data file you wish to use, you can easily import it with the R base functions read.table()

This reads a file in table format and creates a data frame from it

# Read tabular data into R
df_txt <- read.table(file_name.txt, header = FALSE)

There are many packages that let R import all types of data, and we will start by focusing on CSV files as they are the most frequent type.

Comma separated files are the most common way to save spreadsheets that don’t require a licenced, usually not free program to open. Importing CSV is part of base R and you can use read.csv() function to do so.

read.csv()

Let us go to https://data.gov.uk/ UK open data portal. In particular, let us try to access Leeds libraries and import this data to R.

Instead of downloading it onto our local computers, we will import it to R directly from the web using the link provided.

df_csv <- read.csv("https://datamillnorth.org/download/leeds-libraries/cfc9f345-4916-4b74-aa9e-cecc78db9075/library%2520locations.csv", stringsAsFactors = FALSE, fileEncoding = "latin1")
head(df_csv, 10)
##                Library           Operator             Address.Line.1
## 1  Ardsley and Tingley Leeds City Council         213a Bradford Road
## 2               Armley Leeds City Council              2 Stocks Hill
## 3              Beeston Leeds City Council Units 5-6, District Centre
## 4           Boston Spa Leeds City Council                High Street
## 5              Bramley Leeds City Council                 Hough Lane
## 6            Calverley Leeds City Council           Thornhill Street
## 7              Central Leeds City Council                The Headrow
## 8      Chapel Allerton Leeds City Council         106 Harrogate Road
## 9           Chapeltown Leeds City Council        The Reginald Centre
## 10        Compton Road Leeds City Council         The Compton Centre
##         Address.Line.2 Address.Line.3 Postcode VPostcode Latitude Longitude
## 1             Tingley       Wakefield  WF3 2DL   WF032DL 53.72435 -1.550108
## 2               Armley          Leeds LS12 1UQ   LS121UQ 53.79713 -1.588210
## 3          Town Street          Leeds LS11 8PN   LS118PN 53.77229 -1.570413
## 4             Wetherby          Leeds LS23 6BH   LS236BH 53.90686 -1.351368
## 5              Bramley          Leeds LS13 3ND   LS133ND 53.81044 -1.630085
## 6            Calverley          Leeds LS28 5PD   LS285PD 53.82907 -1.687154
## 7     Calverley Street          Leeds  LS1 3AB   LS013AB 53.80013 -1.548706
## 8      Chapel Allerton          Leeds  LS7 4LZ   LS074LZ 53.82833 -1.537206
## 9  263 Chapeltown Road          Leeds  LS7 3EX   LS073EX 53.81767 -1.531703
## 10      Harehills Lane          Leeds  LS9 7BG   LS097BG 53.80953 -1.510093
##                       Ward
## 1   Ardsley and Robin Hood
## 2                   Armley
## 3      Beeston and Holbeck
## 4                 Wetherby
## 5  Bramley and Stanningley
## 6    Calverley and Farsley
## 7         City and Hunslet
## 8          Chapel Allerton
## 9          Chapel Allerton
## 10    Gipton and Harehills
##                                                             ONS.Ref
## 1  http://statistics.data.gov.uk/id/statistical-geography/E05001413
## 2  http://statistics.data.gov.uk/id/statistical-geography/E05001414
## 3  http://statistics.data.gov.uk/id/statistical-geography/E05001415
## 4  http://statistics.data.gov.uk/id/statistical-geography/E05001443
## 5  http://statistics.data.gov.uk/id/statistical-geography/E05001416
## 6  http://statistics.data.gov.uk/id/statistical-geography/E05001418
## 7  http://statistics.data.gov.uk/id/statistical-geography/E05001420
## 8  http://statistics.data.gov.uk/id/statistical-geography/E05001419
## 9  http://statistics.data.gov.uk/id/statistical-geography/E05001419
## 10 http://statistics.data.gov.uk/id/statistical-geography/E05001424
##        Telephone                        Email        Monday.opening.hours
## 1  0113 253 9025 enquiry.express@leeds.gov.uk 10:00 -13:00, 14:00 - 17:00
## 2  0113 378 5670 enquiry.express@leeds.gov.uk               10:00 - 19:00
## 3  0113 378 1849 enquiry.express@leeds.gov.uk               10:00 - 17:00
## 4  0193 784 5239 enquiry.express@leeds.gov.uk               09:00 - 12:00
## 5  0113 378 1851 enquiry.express@leeds.gov.uk               09:00 - 17:00
## 6  0113 378 3124 enquiry.express@leeds.gov.uk               14:00 - 17:00
## 7  0113 378 5005 enquiry.express@leeds.gov.uk               09:00 - 19:00
## 8  0113 378 1859 enquiry.express@leeds.gov.uk               10:00 - 17:00
## 9  0113 336 7683 enquiry.express@leeds.gov.uk               09:00 - 17:00
## 10 0113 336 7790 enquiry.express@leeds.gov.uk               09:00 - 19:00
##    Tuesday.opening.hours      Wednesday.opening.hours Thursday.opening.hours
## 1                 Closed 10:00 - 13:00, 14:00 - 18:00                 Closed
## 2          08:30 - 19:00                08:30 - 19:00          08:30 - 19:00
## 3          10:00 - 17:00                10:00 - 17:00          10:00 - 17:00
## 4                 Closed                10:00 - 17:00                 Closed
## 5          09:00 - 18:00                09:00 - 17:00          10:00 - 17:00
## 6          09:00 - 13:00                       Closed          14:00 - 18:00
## 7          09:00 - 19:00                09:00 - 19:00          09:00 - 18:00
## 8          10:00 - 17:00                10:00 - 19:00          10:00 - 17:00
## 9          09:00 - 19:00                10:00 - 17:00          09:00 - 17:00
## 10         09:00 - 19:00                09:00 - 19:00          09:00 - 19:00
##    Friday..opening.hours Saturday.opening.hours Sunday.opening.hours
## 1          10:00 - 13:00          10:00 - 13:00               Closed
## 2          08:30 - 19:00          10:00 - 16:00               Closed
## 3          10:00 - 18:00          11:00 - 14:00        11:00 - 14:00
## 4          09:00 - 12:00          09:00 - 12:00               Closed
## 5          09:00 - 17:00          10:00 - 15:00        11:00 - 14:00
## 6          09:00 - 13:00          10:00 - 13:00        10:00 - 13:00
## 7          09:00 - 17:00          10:00 - 17:00        11:00 - 15:00
## 8          10:00 - 17:00          11:00 - 16:00               Closed
## 9          09:00 - 17:00          11:00 - 13:00               Closed
## 10         09:00 - 19:00          10:00 - 16:00        12:00 - 16:00
##    Assistive.Technology Adult.books.for.loan..fiction.and.non.fiction
## 1                     1                                             1
## 2                     1                                             1
## 3                     1                                             1
## 4                     1                                             1
## 5                     1                                             1
## 6                     1                                             1
## 7                     1                                             1
## 8                     1                                             1
## 9                     1                                             1
## 10                    1                                             1
##    Baby.changing.facility Boardmaker Book.tokens.for.sale Cafe Car.parking
## 1                      NA         NA                   NA   NA           1
## 2                      NA          1                    1   NA          NA
## 3                      NA          1                    1   NA           1
## 4                      NA         NA                    1   NA          NA
## 5                      NA          1                    1   NA          NA
## 6                      NA         NA                    1   NA          NA
## 7                      NA          1                    1   NA          NA
## 8                      NA          1                    1   NA          NA
## 9                       1          1                    1   NA           1
## 10                      1          1                    1   NA           1
##    Children.s.books.for.loan..fiction.and.non.fiction
## 1                                                   1
## 2                                                   1
## 3                                                   1
## 4                                                   1
## 5                                                   1
## 6                                                   1
## 7                                                   1
## 8                                                   1
## 9                                                   1
## 10                                                  1
##    Children.s.holiday.activities..check.locally Community.Information
## 1                                             1                     1
## 2                                             1                     1
## 3                                             1                     1
## 4                                             1                     1
## 5                                             1                     1
## 6                                             1                     1
## 7                                             1                     1
## 8                                             1                     1
## 9                                             1                     1
## 10                                            1                     1
##    CDs...Music Computers Council.Papers...online Councillor.surgery
## 1           NA         1                       1                 NA
## 2           NA         1                       1                  1
## 3           NA         1                       1                  1
## 4           NA         1                       1                 NA
## 5           NA         1                       1                  1
## 6           NA         1                       1                  1
## 7            1         1                       1                 NA
## 8           NA         1                       1                  1
## 9           NA         1                       1                  1
## 10          NA         1                       1                  1
##    Credit.card.payments Disabled.access Drinks.machine
## 1                    NA               1             NA
## 2                    NA               1             NA
## 3                    NA               1             NA
## 4                    NA               1             NA
## 5                    NA               1             NA
## 6                    NA               1             NA
## 7                     1               1             NA
## 8                    NA               1             NA
## 9                    NA               1              1
## 10                    1               1              1
##    Electoral.Registers..local Electronic.magnifier Employment...training.advice
## 1                          NA                   NA                           NA
## 2                          NA                   NA                           NA
## 3                          NA                   NA                           NA
## 4                          NA                   NA                           NA
## 5                          NA                   NA                           NA
## 6                          NA                   NA                           NA
## 7                           1                   NA                           NA
## 8                          NA                    1                           NA
## 9                          NA                   NA                            1
## 10                         NA                   NA                            1
##    Events..check.locally Exhibition.space Fax Free.Internet.Access
## 1                      1               NA   1                    1
## 2                      1               NA   1                    1
## 3                      1               NA   1                    1
## 4                      1               NA   1                    1
## 5                      1               NA   1                    1
## 6                      1               NA   1                    1
## 7                      1               NA   1                    1
## 8                      1               NA   1                    1
## 9                      1               NA   1                    1
## 10                     1               NA   1                    1
##    Homework.Collection Learning.Sessions.eg.learn.how.to.use.a.computer
## 1                    1                                                1
## 2                    1                                                1
## 3                    1                                                1
## 4                    1                                                1
## 5                    1                                                1
## 6                    1                                                1
## 7                    1                                                1
## 8                    1                                                1
## 9                    1                                                1
## 10                   1                                                1
##    LeedsCard.Registration Local...Family.History Local.bus.timetables
## 1                      NA                      1                    1
## 2                       1                     NA                   NA
## 3                       1                     NA                    1
## 4                      NA                     NA                   NA
## 5                       1                     NA                   NA
## 6                       1                      1                    1
## 7                       1                     NA                   NA
## 8                       1                     NA                    1
## 9                       1                     NA                    1
## 10                      1                     NA                    1
##    Local.publications.for.sale Meeting.room.for.hire
## 1                           NA                    NA
## 2                           NA                    NA
## 3                           NA                     1
## 4                           NA                    NA
## 5                           NA                    NA
## 6                           NA                    NA
## 7                           NA                     1
## 8                           NA                    NA
## 9                           NA                    NA
## 10                          NA                    NA
##    Microsoft.Office.Facilities MP.surgery Newspapers Photocopier..B...W
## 1                            1         NA         NA                  1
## 2                            1          1          1                  1
## 3                            1          1          1                  1
## 4                            1         NA         NA                 NA
## 5                            1          1          1                  1
## 6                            1         NA         NA                  1
## 7                            1         NA          1                  1
## 8                            1         NA          1                  1
## 9                            1          1          1                  1
## 10                           1         NA          1                  1
##    Planning.Applications..online. Printing Readers..Group Request.Service
## 1                               1        1              1               1
## 2                               1        1              1               1
## 3                               1        1              1               1
## 4                               1        1             NA               1
## 5                               1        1              1               1
## 6                               1        1              1               1
## 7                               1        1              1               1
## 8                               1        1              1               1
## 9                               1        1              1               1
## 10                              1        1              1               1
##    Scanner Self.service.facility Story.tapes.for.children Story.time
## 1        1                     1                        1          1
## 2       NA                    NA                        1          1
## 3        1                     1                        1          1
## 4       NA                    NA                        1         NA
## 5       NA                    NA                        1          1
## 6        1                     1                        1          1
## 7       NA                    NA                        1          1
## 8        1                     1                        1          1
## 9        1                     1                        1          1
## 10       1                     1                        1          1
##    Study.space Sunday.opening Talking.books Theatre.bookings Toilet
## 1           NA             NA             1               NA      1
## 2           NA             NA             1                1      1
## 3           NA              1             1                1      1
## 4           NA             NA             1               NA     NA
## 5           NA             NA             1                1      1
## 6           NA             NA             1                1      1
## 7           NA             NA             1                1     NA
## 8           NA             NA             1               NA     NA
## 9           NA             NA             1               NA      1
## 10          NA              1             1                1      1
##    Tourist.Information Free.WIFI Writers..Group
## 1                   NA         1             NA
## 2                   NA         1             NA
## 3                   NA         1             NA
## 4                   NA         1             NA
## 5                   NA         1             NA
## 6                   NA         1              1
## 7                   NA         1             NA
## 8                   NA         1             NA
## 9                   NA         1              1
## 10                  NA         1             NA

The other way is to download it and save it to your working directory.

Let us download Leeds libraries csv file Make sure you save the file into your R-Project working directory before you ask R to execute the following

df_csv <- read.csv("library locations.csv", stringsAsFactors = FALSE, fileEncoding = "latin1")

Run the above code again, but set stringsAsFactors argument from the read.csv function to TRUE. Can you tell the difference between now and before? Why do you think it is useful to use fileEncoding argument?

What do you think about this dataset? 🤔

Using readr::read_csv()

readr is a package that reads rectangular data more quickly than base R read.cdv(). Another difference from the read.csv() function is that it assumes characters are strings and not factors by default.

Just so you can see how easy it is to use other packages for importing data into R, the code below illustrates the use of read_csv().

## If you don't have readr installed yet, uncomment and run the line below
# install.packages("readr")
library(readr)
df_csv <- read_csv("library locations.csv")
df_csv

Check the readr::read_delim() function for more efficient delimited data file reading.

Importing Excel files with readxl

Importing Excel data files is not straightforward as it might contain multiple sheets. We will focus on using the readxl package as it is the most efficient so far.

To access the data from an Excel sheet you can’t just copy and paste the URL for the file. You have to download the file first.

Let us download an Excel data file from data.gov.uk about Greater London Authority Poll Results 2018 from this link:December 2018 - YouGov GLA poll results.

If you are unable to open the file in Excel to examine how many sheets the file has, try to read the file in R accessing the first one by specifying it in the read_excel() function as required. As previously, make sure you save the file into your R-Project working directory before you ask R to execute the following:

## If you don't have readxl installed yet, uncomment the line below and run it 
#install.packages("readxl")
library(readxl)
df_xl <- read_excel("Dec 2018 - YouGov GLA poll results", sheet = 1)

What do you think?

People like to make their Excel spreadsheets look ‘pretty’ with ‘fancy’ formatting, which could create difficulty when reading them in R.

Explore the arguments of the read_excel() function, such as the skip argument through which you can specify a minimum number of rows to skip before reading anything.

Importing data using jsonlite

When accessing a JSON file in R using the jsonlite package you need to point to the file by providing the local path if the file is downloaded or by the URL from where it can be accessed.

## If you don't have readxl installed yet, uncomment the line below and run it 
#install.packages("jsonlite")
library(jsonlite)
my_url <-"https://coronavirus.data.gov.uk/downloads/msoa_data/MSOAs_latest.json"
covid_uk <- fromJSON(my_url)

Check the structure of the covid_uk! 😰

str(covid_uk)
## List of 3
##  $ releaseTimestamp: chr "2020-12-03T16:20:30.918698Z"
##  $ length          : int 6791
##  $ data            :'data.frame':	6791 obs. of  5 variables:
##   ..$ areaType             : chr [1:6791] "MSOA" "MSOA" "MSOA" "MSOA" ...
##   ..$ areaCode             : chr [1:6791] "E02000001" "E02000002" "E02000003" "E02000004" ...
##   ..$ areaName             : chr [1:6791] "City of London" "Marks Gate" "Chadwell Heath East" "Eastbrookend" ...
##   ..$ length               : int [1:6791] 37 37 37 37 37 37 37 37 37 37 ...
##   ..$ newCasesByPublishDate:List of 6791
##   .. ..$ :'data.frame':	37 obs. of  3 variables:
##   .. .. ..$ date       : chr [1:37] "2020-03-21" "2020-03-28" "2020-04-04" "2020-04-11" ...
##   .. .. ..$ rollingSum : num [1:37] 4 NA 4 NA NA 3 NA NA NA NA ...
##   .. .. ..$ rollingRate: num [1:37] 41.1 NA 41.1 NA NA 30.9 NA NA NA NA ...
##   .. ..$ :'data.frame':	37 obs. of  3 variables:
##   .. .. ..$ date       : chr [1:37] "2020-03-21" "2020-03-28" "2020-04-04" "2020-04-11" ...
##   .. .. ..$ rollingSum : num [1:37] NA NA 4 3 6 NA NA NA NA NA ...
##   .. .. ..$ rollingRate: num [1:37] NA NA 51.7 38.8 77.6 NA NA NA NA NA ...
##   .. ..$ :'data.frame':	37 obs. of  3 variables:
##   .. .. ..$ date       : chr [1:37] "2020-03-21" "2020-03-28" "2020-04-04" "2020-04-11" ...
##   .. .. ..$ rollingSum : num [1:37] NA NA 9 10 4 6 4 NA NA NA ...
##   .. .. ..$ rollingRate: num [1:37] NA NA 80.5 89.5 35.8 53.7 35.8 NA NA NA ...
##   .. ..$ :'data.frame':	37 obs. of  3 variables:
##   .. .. ..$ date       : chr [1:37] "2020-03-21" "2020-03-28" "2020-04-04" "2020-04-11" ...
##   .. .. ..$ rollingSum : num [1:37] NA 6 8 7 NA 7 NA 3 4 NA ...
##   .. .. ..$ rollingRate: num [1:37] NA 89.7 119.6 104.7 NA ...
##   .. ..$ :'data.frame':	37 obs. of  3 variables:
##   .. .. ..$ date       : chr [1:37] "2020-03-21" "2020-03-28" "2020-04-04" "2020-04-11" ...
##   .. .. ..$ rollingSum : num [1:37] NA NA 9 8 5 NA NA NA NA NA ...
##   .. .. ..$ rollingRate: num [1:37] NA NA 86.3 76.7 47.9 NA NA NA NA NA ...
##   .. ..$ :'data.frame':	37 obs. of  3 variables:
##   .. .. ..$ date       : chr [1:37] "2020-03-21" "2020-03-28" "2020-04-04" "2020-04-11" ...
##   .. .. ..$ rollingSum : num [1:37] 5 3 4 3 5 3 5 NA NA NA ...
##   .. .. ..$ rollingRate: num [1:37] 49.8 29.9 39.8 29.9 49.8 29.9 49.8 NA NA NA ...
##   .. ..$ :'data.frame':	37 obs. of  3 variables:
##   .. .. ..$ date       : chr [1:37] "2020-03-21" "2020-03-28" "2020-04-04" "2020-04-11" ...
##   .. .. ..$ rollingSum : num [1:37] 4 3 7 5 5 3 3 5 4 3 ...
##   .. .. ..$ rollingRate: num [1:37] 31.6 23.7 55.3 39.5 39.5 23.7 23.7 39.5 31.6 23.7 ...
##   .. ..$ :'data.frame':	37 obs. of  3 variables:
##   .. .. ..$ date       : chr [1:37] "2020-03-21" "2020-03-28" "2020-04-04" "2020-04-11" ...
##   .. .. ..$ rollingSum : num [1:37] 4 4 5 3 6 3 NA NA NA NA ...
##   .. .. ..$ rollingRate: num [1:37] 33.8 33.8 42.3 25.4 50.7 25.4 NA NA NA NA ...
##   .. ..$ :'data.frame':	37 obs. of  3 variables:
##   .. .. ..$ date       : chr [1:37] "2020-03-21" "2020-03-28" "2020-04-04" "2020-04-11" ...
##   .. .. ..$ rollingSum : num [1:37] NA NA 7 8 3 NA NA NA NA NA ...
##   .. .. ..$ rollingRate: num [1:37] NA NA 76.1 86.9 32.6 NA NA NA NA NA ...
##   .. ..$ :'data.frame':	37 obs. of  3 variables:
##   .. .. ..$ date       : chr [1:37] "2020-03-21" "2020-03-28" "2020-04-04" "2020-04-11" ...
##   .. .. ..$ rollingSum : num [1:37] NA 3 7 3 NA 3 NA NA 3 NA ...
##   .. .. ..$ rollingRate: num [1:37] NA 42.9 100.1 42.9 NA ...
##   .. ..$ :'data.frame':	37 obs. of  3 variables:
##   .. .. ..$ date       : chr [1:37] "2020-03-21" "2020-03-28" "2020-04-04" "2020-04-11" ...
##   .. .. ..$ rollingSum : num [1:37] 4 3 8 5 NA 7 5 NA NA 3 ...
##   .. .. ..$ rollingRate: num [1:37] 35.4 26.6 70.9 44.3 NA 62 44.3 NA NA 26.6 ...
##   .. ..$ :'data.frame':	37 obs. of  3 variables:
##   .. .. ..$ date       : chr [1:37] "2020-03-21" "2020-03-28" "2020-04-04" "2020-04-11" ...
##   .. .. ..$ rollingSum : num [1:37] NA NA 4 7 NA NA NA NA NA NA ...
##   .. .. ..$ rollingRate: num [1:37] NA NA 44.7 78.2 NA NA NA NA NA NA ...
##   .. ..$ :'data.frame':	37 obs. of  3 variables:
##   .. .. ..$ date       : chr [1:37] "2020-03-21" "2020-03-28" "2020-04-04" "2020-04-11" ...
##   .. .. ..$ rollingSum : num [1:37] NA 3 5 3 7 NA 4 NA 5 NA ...
##   .. .. ..$ rollingRate: num [1:37] NA 30.2 50.3 30.2 70.4 NA 40.2 NA 50.3 NA ...
##   .. ..$ :'data.frame':	37 obs. of  3 variables:
##   .. .. ..$ date       : chr [1:37] "2020-03-21" "2020-03-28" "2020-04-04" "2020-04-11" ...
##   .. .. ..$ rollingSum : num [1:37] NA 3 NA 3 7 3 NA NA 3 NA ...
##   .. .. ..$ rollingRate: num [1:37] NA 36.6 NA 36.6 85.5 36.6 NA NA 36.6 NA ...
##   .. ..$ :'data.frame':	37 obs. of  3 variables:
##   .. .. ..$ date       : chr [1:37] "2020-03-21" "2020-03-28" "2020-04-04" "2020-04-11" ...
##   .. .. ..$ rollingSum : num [1:37] NA 5 4 4 NA NA 4 NA NA NA ...
##   .. .. ..$ rollingRate: num [1:37] NA 49.9 39.9 39.9 NA NA 39.9 NA NA NA ...
##   .. ..$ :'data.frame':	37 obs. of  3 variables:
##   .. .. ..$ date       : chr [1:37] "2020-03-21" "2020-03-28" "2020-04-04" "2020-04-11" ...
##   .. .. ..$ rollingSum : num [1:37] NA 3 4 5 4 4 5 4 NA NA ...
##   .. .. ..$ rollingRate: num [1:37] NA 32.3 43.1 53.9 43.1 43.1 53.9 43.1 NA NA ...
##   .. ..$ :'data.frame':	37 obs. of  3 variables:
##   .. .. ..$ date       : chr [1:37] "2020-03-21" "2020-03-28" "2020-04-04" "2020-04-11" ...
##   .. .. ..$ rollingSum : num [1:37] NA 6 4 4 4 NA NA NA NA NA ...
##   .. .. ..$ rollingRate: num [1:37] NA 62.2 41.5 41.5 41.5 NA NA NA NA NA ...
##   .. ..$ :'data.frame':	37 obs. of  3 variables:
##   .. .. ..$ date       : chr [1:37] "2020-03-21" "2020-03-28" "2020-04-04" "2020-04-11" ...
##   .. .. ..$ rollingSum : num [1:37] 3 4 5 NA NA 5 4 3 4 NA ...
##   .. .. ..$ rollingRate: num [1:37] 32.7 43.6 54.5 NA NA 54.5 43.6 32.7 43.6 NA ...
##   .. ..$ :'data.frame':	37 obs. of  3 variables:
##   .. .. ..$ date       : chr [1:37] "2020-03-21" "2020-03-28" "2020-04-04" "2020-04-11" ...
##   .. .. ..$ rollingSum : num [1:37] NA 8 4 5 11 4 5 NA NA NA ...
##   .. .. ..$ rollingRate: num [1:37] NA 59.9 30 37.4 82.4 30 37.4 NA NA NA ...
##   .. ..$ :'data.frame':	37 obs. of  3 variables:
##   .. .. ..$ date       : chr [1:37] "2020-03-21" "2020-03-28" "2020-04-04" "2020-04-11" ...
##   .. .. ..$ rollingSum : num [1:37] 4 NA 9 3 NA NA NA NA NA NA ...
##   .. .. ..$ rollingRate: num [1:37] 44.7 NA 100.6 33.5 NA ...
##   .. ..$ :'data.frame':	37 obs. of  3 variables:
##   .. .. ..$ date       : chr [1:37] "2020-03-21" "2020-03-28" "2020-04-04" "2020-04-11" ...
##   .. .. ..$ rollingSum : num [1:37] NA NA 3 NA NA NA NA NA NA NA ...
##   .. .. ..$ rollingRate: num [1:37] NA NA 36.7 NA NA NA NA NA NA NA ...
##   .. ..$ :'data.frame':	37 obs. of  3 variables:
##   .. .. ..$ date       : chr [1:37] "2020-03-21" "2020-03-28" "2020-04-04" "2020-04-11" ...
##   .. .. ..$ rollingSum : num [1:37] NA 5 5 7 4 4 NA NA NA NA ...
##   .. .. ..$ rollingRate: num [1:37] NA 62.3 62.3 87.2 49.9 49.9 NA NA NA NA ...
##   .. ..$ :'data.frame':	37 obs. of  3 variables:
##   .. .. ..$ date       : chr [1:37] "2020-03-21" "2020-03-28" "2020-04-04" "2020-04-11" ...
##   .. .. ..$ rollingSum : num [1:37] 3 NA 8 14 4 4 4 3 NA NA ...
##   .. .. ..$ rollingRate: num [1:37] 27.1 NA 72.4 126.6 36.2 ...
##   .. ..$ :'data.frame':	37 obs. of  3 variables:
##   .. .. ..$ date       : chr [1:37] "2020-03-21" "2020-03-28" "2020-04-04" "2020-04-11" ...
##   .. .. ..$ rollingSum : num [1:37] 4 5 8 6 3 NA NA NA NA NA ...
##   .. .. ..$ rollingRate: num [1:37] 47.9 59.9 95.8 71.9 35.9 NA NA NA NA NA ...
##   .. ..$ :'data.frame':	37 obs. of  3 variables:
##   .. .. ..$ date       : chr [1:37] "2020-03-21" "2020-03-28" "2020-04-04" "2020-04-11" ...
##   .. .. ..$ rollingSum : num [1:37] NA NA 8 NA NA NA 4 NA NA NA ...
##   .. .. ..$ rollingRate: num [1:37] NA NA 121 NA NA ...
##   .. ..$ :'data.frame':	37 obs. of  3 variables:
##   .. .. ..$ date       : chr [1:37] "2020-03-21" "2020-03-28" "2020-04-04" "2020-04-11" ...
##   .. .. ..$ rollingSum : num [1:37] 3 3 8 13 8 3 NA NA NA NA ...
##   .. .. ..$ rollingRate: num [1:37] 31.1 31.1 83 134.9 83 ...
##   .. ..$ :'data.frame':	37 obs. of  3 variables:
##   .. .. ..$ date       : chr [1:37] "2020-03-21" "2020-03-28" "2020-04-04" "2020-04-11" ...
##   .. .. ..$ rollingSum : num [1:37] NA 4 9 5 NA 7 4 NA NA NA ...
##   .. .. ..$ rollingRate: num [1:37] NA 58.7 132.2 73.4 NA ...
##   .. ..$ :'data.frame':	37 obs. of  3 variables:
##   .. .. ..$ date       : chr [1:37] "2020-03-21" "2020-03-28" "2020-04-04" "2020-04-11" ...
##   .. .. ..$ rollingSum : num [1:37] NA 7 4 7 3 NA 5 NA NA NA ...
##   .. .. ..$ rollingRate: num [1:37] NA 74.1 42.3 74.1 31.7 NA 52.9 NA NA NA ...
##   .. ..$ :'data.frame':	37 obs. of  3 variables:
##   .. .. ..$ date       : chr [1:37] "2020-03-21" "2020-03-28" "2020-04-04" "2020-04-11" ...
##   .. .. ..$ rollingSum : num [1:37] 4 7 13 11 4 3 4 3 6 NA ...
##   .. .. ..$ rollingRate: num [1:37] 43.3 75.7 140.7 119 43.3 ...
##   .. ..$ :'data.frame':	37 obs. of  3 variables:
##   .. .. ..$ date       : chr [1:37] "2020-03-21" "2020-03-28" "2020-04-04" "2020-04-11" ...
##   .. .. ..$ rollingSum : num [1:37] NA 3 14 8 5 NA 3 NA NA NA ...
##   .. .. ..$ rollingRate: num [1:37] NA 38.2 178.2 101.8 63.6 ...
##   .. ..$ :'data.frame':	37 obs. of  3 variables:
##   .. .. ..$ date       : chr [1:37] "2020-03-21" "2020-03-28" "2020-04-04" "2020-04-11" ...
##   .. .. ..$ rollingSum : num [1:37] 5 5 10 6 NA 5 NA 3 NA NA ...
##   .. .. ..$ rollingRate: num [1:37] 64.3 64.3 128.7 77.2 NA ...
##   .. ..$ :'data.frame':	37 obs. of  3 variables:
##   .. .. ..$ date       : chr [1:37] "2020-03-21" "2020-03-28" "2020-04-04" "2020-04-11" ...
##   .. .. ..$ rollingSum : num [1:37] NA 6 NA 3 NA NA NA NA NA NA ...
##   .. .. ..$ rollingRate: num [1:37] NA 67.4 NA 33.7 NA NA NA NA NA NA ...
##   .. ..$ :'data.frame':	37 obs. of  3 variables:
##   .. .. ..$ date       : chr [1:37] "2020-03-21" "2020-03-28" "2020-04-04" "2020-04-11" ...
##   .. .. ..$ rollingSum : num [1:37] NA 11 9 3 NA 4 3 NA NA NA ...
##   .. .. ..$ rollingRate: num [1:37] NA 117.6 96.2 32.1 NA ...
##   .. ..$ :'data.frame':	37 obs. of  3 variables:
##   .. .. ..$ date       : chr [1:37] "2020-03-21" "2020-03-28" "2020-04-04" "2020-04-11" ...
##   .. .. ..$ rollingSum : num [1:37] NA 6 7 12 NA 5 3 NA NA NA ...
##   .. .. ..$ rollingRate: num [1:37] NA 66.1 77.1 132.2 NA ...
##   .. ..$ :'data.frame':	37 obs. of  3 variables:
##   .. .. ..$ date       : chr [1:37] "2020-03-21" "2020-03-28" "2020-04-04" "2020-04-11" ...
##   .. .. ..$ rollingSum : num [1:37] NA 4 8 7 3 NA 3 3 NA NA ...
##   .. .. ..$ rollingRate: num [1:37] NA 34.3 68.7 60.1 25.8 NA 25.8 25.8 NA NA ...
##   .. ..$ :'data.frame':	37 obs. of  3 variables:
##   .. .. ..$ date       : chr [1:37] "2020-03-21" "2020-03-28" "2020-04-04" "2020-04-11" ...
##   .. .. ..$ rollingSum : num [1:37] NA 9 6 6 4 NA NA NA NA NA ...
##   .. .. ..$ rollingRate: num [1:37] NA 85.3 56.9 56.9 37.9 NA NA NA NA NA ...
##   .. ..$ :'data.frame':	37 obs. of  3 variables:
##   .. .. ..$ date       : chr [1:37] "2020-03-21" "2020-03-28" "2020-04-04" "2020-04-11" ...
##   .. .. ..$ rollingSum : num [1:37] NA 7 5 9 7 7 NA NA NA NA ...
##   .. .. ..$ rollingRate: num [1:37] NA 61 43.6 78.4 61 61 NA NA NA NA ...
##   .. ..$ :'data.frame':	37 obs. of  3 variables:
##   .. .. ..$ date       : chr [1:37] "2020-03-21" "2020-03-28" "2020-04-04" "2020-04-11" ...
##   .. .. ..$ rollingSum : num [1:37] NA 4 8 NA NA NA NA NA NA NA ...
##   .. .. ..$ rollingRate: num [1:37] NA 55.1 110.3 NA NA ...
##   .. ..$ :'data.frame':	37 obs. of  3 variables:
##   .. .. ..$ date       : chr [1:37] "2020-03-21" "2020-03-28" "2020-04-04" "2020-04-11" ...
##   .. .. ..$ rollingSum : num [1:37] NA 7 6 6 8 NA NA NA NA NA ...
##   .. .. ..$ rollingRate: num [1:37] NA 82.8 71 71 94.7 NA NA NA NA NA ...
##   .. ..$ :'data.frame':	37 obs. of  3 variables:
##   .. .. ..$ date       : chr [1:37] "2020-03-21" "2020-03-28" "2020-04-04" "2020-04-11" ...
##   .. .. ..$ rollingSum : num [1:37] 3 3 9 3 4 NA 7 NA NA NA ...
##   .. .. ..$ rollingRate: num [1:37] 29.9 29.9 89.7 29.9 39.9 NA 69.8 NA NA NA ...
##   .. ..$ :'data.frame':	37 obs. of  3 variables:
##   .. .. ..$ date       : chr [1:37] "2020-03-21" "2020-03-28" "2020-04-04" "2020-04-11" ...
##   .. .. ..$ rollingSum : num [1:37] NA 12 11 8 4 4 3 NA NA NA ...
##   .. .. ..$ rollingRate: num [1:37] NA 98 89.8 65.3 32.7 32.7 24.5 NA NA NA ...
##   .. ..$ :'data.frame':	37 obs. of  3 variables:
##   .. .. ..$ date       : chr [1:37] "2020-03-21" "2020-03-28" "2020-04-04" "2020-04-11" ...
##   .. .. ..$ rollingSum : num [1:37] NA 3 NA 5 NA NA NA NA NA NA ...
##   .. .. ..$ rollingRate: num [1:37] NA 36.6 NA 60.9 NA NA NA NA NA NA ...
##   .. ..$ :'data.frame':	37 obs. of  3 variables:
##   .. .. ..$ date       : chr [1:37] "2020-03-21" "2020-03-28" "2020-04-04" "2020-04-11" ...
##   .. .. ..$ rollingSum : num [1:37] 6 NA 4 NA 4 4 4 NA NA NA ...
##   .. .. ..$ rollingRate: num [1:37] 67.6 NA 45.1 NA 45.1 45.1 45.1 NA NA NA ...
##   .. ..$ :'data.frame':	37 obs. of  3 variables:
##   .. .. ..$ date       : chr [1:37] "2020-03-21" "2020-03-28" "2020-04-04" "2020-04-11" ...
##   .. .. ..$ rollingSum : num [1:37] NA 11 7 NA NA 4 NA NA NA NA ...
##   .. .. ..$ rollingRate: num [1:37] NA 100 64 NA NA ...
##   .. ..$ :'data.frame':	37 obs. of  3 variables:
##   .. .. ..$ date       : chr [1:37] "2020-03-21" "2020-03-28" "2020-04-04" "2020-04-11" ...
##   .. .. ..$ rollingSum : num [1:37] NA 3 NA NA NA NA NA NA NA 4 ...
##   .. .. ..$ rollingRate: num [1:37] NA 39.4 NA NA NA NA NA NA NA 52.5 ...
##   .. ..$ :'data.frame':	37 obs. of  3 variables:
##   .. .. ..$ date       : chr [1:37] "2020-03-21" "2020-03-28" "2020-04-04" "2020-04-11" ...
##   .. .. ..$ rollingSum : num [1:37] 3 11 5 6 4 5 7 8 3 NA ...
##   .. .. ..$ rollingRate: num [1:37] 24.2 88.6 40.3 48.3 32.2 40.3 56.4 64.4 24.2 NA ...
##   .. ..$ :'data.frame':	37 obs. of  3 variables:
##   .. .. ..$ date       : chr [1:37] "2020-03-21" "2020-03-28" "2020-04-04" "2020-04-11" ...
##   .. .. ..$ rollingSum : num [1:37] 4 6 6 6 3 NA NA NA NA NA ...
##   .. .. ..$ rollingRate: num [1:37] 37.4 56 56 56 28 NA NA NA NA NA ...
##   .. ..$ :'data.frame':	37 obs. of  3 variables:
##   .. .. ..$ date       : chr [1:37] "2020-03-21" "2020-03-28" "2020-04-04" "2020-04-11" ...
##   .. .. ..$ rollingSum : num [1:37] 3 7 7 6 5 4 5 3 NA NA ...
##   .. .. ..$ rollingRate: num [1:37] 31.7 73.9 73.9 63.3 52.8 42.2 52.8 31.7 NA NA ...
##   .. ..$ :'data.frame':	37 obs. of  3 variables:
##   .. .. ..$ date       : chr [1:37] "2020-03-21" "2020-03-28" "2020-04-04" "2020-04-11" ...
##   .. .. ..$ rollingSum : num [1:37] NA NA 3 NA NA NA NA NA 3 NA ...
##   .. .. ..$ rollingRate: num [1:37] NA NA 27.2 NA NA NA NA NA 27.2 NA ...
##   .. ..$ :'data.frame':	37 obs. of  3 variables:
##   .. .. ..$ date       : chr [1:37] "2020-03-21" "2020-03-28" "2020-04-04" "2020-04-11" ...
##   .. .. ..$ rollingSum : num [1:37] NA 7 5 7 5 NA NA NA NA NA ...
##   .. .. ..$ rollingRate: num [1:37] NA 70.9 50.6 70.9 50.6 NA NA NA NA NA ...
##   .. ..$ :'data.frame':	37 obs. of  3 variables:
##   .. .. ..$ date       : chr [1:37] "2020-03-21" "2020-03-28" "2020-04-04" "2020-04-11" ...
##   .. .. ..$ rollingSum : num [1:37] NA 3 NA 3 NA NA NA NA 3 4 ...
##   .. .. ..$ rollingRate: num [1:37] NA 28.3 NA 28.3 NA NA NA NA 28.3 37.7 ...
##   .. ..$ :'data.frame':	37 obs. of  3 variables:
##   .. .. ..$ date       : chr [1:37] "2020-03-21" "2020-03-28" "2020-04-04" "2020-04-11" ...
##   .. .. ..$ rollingSum : num [1:37] 4 7 9 12 3 4 4 NA NA NA ...
##   .. .. ..$ rollingRate: num [1:37] 24 42 53.9 71.9 18 24 24 NA NA NA ...
##   .. ..$ :'data.frame':	37 obs. of  3 variables:
##   .. .. ..$ date       : chr [1:37] "2020-03-21" "2020-03-28" "2020-04-04" "2020-04-11" ...
##   .. .. ..$ rollingSum : num [1:37] NA 7 8 4 NA NA NA NA NA NA ...
##   .. .. ..$ rollingRate: num [1:37] NA 91.5 104.6 52.3 NA ...
##   .. ..$ :'data.frame':	37 obs. of  3 variables:
##   .. .. ..$ date       : chr [1:37] "2020-03-21" "2020-03-28" "2020-04-04" "2020-04-11" ...
##   .. .. ..$ rollingSum : num [1:37] 8 9 8 6 9 3 4 5 11 NA ...
##   .. .. ..$ rollingRate: num [1:37] 66.7 75 66.7 50 75 25 33.4 41.7 91.7 NA ...
##   .. ..$ :'data.frame':	37 obs. of  3 variables:
##   .. .. ..$ date       : chr [1:37] "2020-03-21" "2020-03-28" "2020-04-04" "2020-04-11" ...
##   .. .. ..$ rollingSum : num [1:37] 5 5 10 9 3 4 NA 3 NA 6 ...
##   .. .. ..$ rollingRate: num [1:37] 52 52 104.1 93.7 31.2 ...
##   .. ..$ :'data.frame':	37 obs. of  3 variables:
##   .. .. ..$ date       : chr [1:37] "2020-03-21" "2020-03-28" "2020-04-04" "2020-04-11" ...
##   .. .. ..$ rollingSum : num [1:37] 5 9 11 8 NA NA NA NA NA NA ...
##   .. .. ..$ rollingRate: num [1:37] 61.2 110.2 134.7 98 NA ...
##   .. ..$ :'data.frame':	37 obs. of  3 variables:
##   .. .. ..$ date       : chr [1:37] "2020-03-21" "2020-03-28" "2020-04-04" "2020-04-11" ...
##   .. .. ..$ rollingSum : num [1:37] 4 18 3 NA 4 5 4 NA NA NA ...
##   .. .. ..$ rollingRate: num [1:37] 36.5 164.4 27.4 NA 36.5 ...
##   .. ..$ :'data.frame':	37 obs. of  3 variables:
##   .. .. ..$ date       : chr [1:37] "2020-03-21" "2020-03-28" "2020-04-04" "2020-04-11" ...
##   .. .. ..$ rollingSum : num [1:37] 6 14 16 7 3 10 7 NA 4 NA ...
##   .. .. ..$ rollingRate: num [1:37] 50.5 117.9 134.8 59 25.3 ...
##   .. ..$ :'data.frame':	37 obs. of  3 variables:
##   .. .. ..$ date       : chr [1:37] "2020-03-21" "2020-03-28" "2020-04-04" "2020-04-11" ...
##   .. .. ..$ rollingSum : num [1:37] 6 21 17 11 9 3 NA 4 NA NA ...
##   .. .. ..$ rollingRate: num [1:37] 48.6 170 137.6 89 72.9 ...
##   .. ..$ :'data.frame':	37 obs. of  3 variables:
##   .. .. ..$ date       : chr [1:37] "2020-03-21" "2020-03-28" "2020-04-04" "2020-04-11" ...
##   .. .. ..$ rollingSum : num [1:37] NA 20 4 7 3 4 9 NA NA 3 ...
##   .. .. ..$ rollingRate: num [1:37] NA 218 43.6 76.3 32.7 43.6 98.1 NA NA 32.7 ...
##   .. ..$ :'data.frame':	37 obs. of  3 variables:
##   .. .. ..$ date       : chr [1:37] "2020-03-21" "2020-03-28" "2020-04-04" "2020-04-11" ...
##   .. .. ..$ rollingSum : num [1:37] NA 3 4 NA 5 NA 4 NA NA NA ...
##   .. .. ..$ rollingRate: num [1:37] NA 42.7 57 NA 71.2 NA 57 NA NA NA ...
##   .. ..$ :'data.frame':	37 obs. of  3 variables:
##   .. .. ..$ date       : chr [1:37] "2020-03-21" "2020-03-28" "2020-04-04" "2020-04-11" ...
##   .. .. ..$ rollingSum : num [1:37] NA 7 11 7 5 3 NA NA NA NA ...
##   .. .. ..$ rollingRate: num [1:37] NA 88 138.3 88 62.9 ...
##   .. ..$ :'data.frame':	37 obs. of  3 variables:
##   .. .. ..$ date       : chr [1:37] "2020-03-21" "2020-03-28" "2020-04-04" "2020-04-11" ...
##   .. .. ..$ rollingSum : num [1:37] 3 3 5 NA 3 NA NA NA NA NA ...
##   .. .. ..$ rollingRate: num [1:37] 43.3 43.3 72.2 NA 43.3 NA NA NA NA NA ...
##   .. ..$ :'data.frame':	37 obs. of  3 variables:
##   .. .. ..$ date       : chr [1:37] "2020-03-21" "2020-03-28" "2020-04-04" "2020-04-11" ...
##   .. .. ..$ rollingSum : num [1:37] NA NA 4 5 10 6 4 NA NA NA ...
##   .. .. ..$ rollingRate: num [1:37] NA NA 44.7 55.9 111.7 ...
##   .. ..$ :'data.frame':	37 obs. of  3 variables:
##   .. .. ..$ date       : chr [1:37] "2020-03-21" "2020-03-28" "2020-04-04" "2020-04-11" ...
##   .. .. ..$ rollingSum : num [1:37] 4 3 4 4 5 3 6 NA 3 9 ...
##   .. .. ..$ rollingRate: num [1:37] 39.3 29.5 39.3 39.3 49.1 29.5 58.9 NA 29.5 88.4 ...
##   .. ..$ :'data.frame':	37 obs. of  3 variables:
##   .. .. ..$ date       : chr [1:37] "2020-03-21" "2020-03-28" "2020-04-04" "2020-04-11" ...
##   .. .. ..$ rollingSum : num [1:37] NA 5 6 6 6 5 NA NA NA 4 ...
##   .. .. ..$ rollingRate: num [1:37] NA 47.8 57.4 57.4 57.4 47.8 NA NA NA 38.3 ...
##   .. ..$ :'data.frame':	37 obs. of  3 variables:
##   .. .. ..$ date       : chr [1:37] "2020-03-21" "2020-03-28" "2020-04-04" "2020-04-11" ...
##   .. .. ..$ rollingSum : num [1:37] NA NA 4 4 5 3 5 3 3 NA ...
##   .. .. ..$ rollingRate: num [1:37] NA NA 48.8 48.8 61 36.6 61 36.6 36.6 NA ...
##   .. ..$ :'data.frame':	37 obs. of  3 variables:
##   .. .. ..$ date       : chr [1:37] "2020-03-21" "2020-03-28" "2020-04-04" "2020-04-11" ...
##   .. .. ..$ rollingSum : num [1:37] NA 3 4 8 4 NA NA 3 NA NA ...
##   .. .. ..$ rollingRate: num [1:37] NA 43.4 57.9 115.8 57.9 ...
##   .. ..$ :'data.frame':	37 obs. of  3 variables:
##   .. .. ..$ date       : chr [1:37] "2020-03-21" "2020-03-28" "2020-04-04" "2020-04-11" ...
##   .. .. ..$ rollingSum : num [1:37] NA 5 5 5 3 3 5 NA NA NA ...
##   .. .. ..$ rollingRate: num [1:37] NA 61.9 61.9 61.9 37.1 37.1 61.9 NA NA NA ...
##   .. ..$ :'data.frame':	37 obs. of  3 variables:
##   .. .. ..$ date       : chr [1:37] "2020-03-21" "2020-03-28" "2020-04-04" "2020-04-11" ...
##   .. .. ..$ rollingSum : num [1:37] NA NA NA 3 3 NA NA NA NA 3 ...
##   .. .. ..$ rollingRate: num [1:37] NA NA NA 39.2 39.2 NA NA NA NA 39.2 ...
##   .. ..$ :'data.frame':	37 obs. of  3 variables:
##   .. .. ..$ date       : chr [1:37] "2020-03-21" "2020-03-28" "2020-04-04" "2020-04-11" ...
##   .. .. ..$ rollingSum : num [1:37] NA 5 9 8 8 5 9 3 NA 3 ...
##   .. .. ..$ rollingRate: num [1:37] NA 38.3 69 61.4 61.4 38.3 69 23 NA 23 ...
##   .. ..$ :'data.frame':	37 obs. of  3 variables:
##   .. .. ..$ date       : chr [1:37] "2020-03-21" "2020-03-28" "2020-04-04" "2020-04-11" ...
##   .. .. ..$ rollingSum : num [1:37] NA 5 12 9 4 9 NA NA NA NA ...
##   .. .. ..$ rollingRate: num [1:37] NA 46 110.5 82.9 36.8 ...
##   .. ..$ :'data.frame':	37 obs. of  3 variables:
##   .. .. ..$ date       : chr [1:37] "2020-03-21" "2020-03-28" "2020-04-04" "2020-04-11" ...
##   .. .. ..$ rollingSum : num [1:37] NA 8 8 5 3 8 NA NA NA 3 ...
##   .. .. ..$ rollingRate: num [1:37] NA 92.1 92.1 57.6 34.6 92.1 NA NA NA 34.6 ...
##   .. ..$ :'data.frame':	37 obs. of  3 variables:
##   .. .. ..$ date       : chr [1:37] "2020-03-21" "2020-03-28" "2020-04-04" "2020-04-11" ...
##   .. .. ..$ rollingSum : num [1:37] NA NA 3 4 3 NA NA NA 3 NA ...
##   .. .. ..$ rollingRate: num [1:37] NA NA 36.5 48.7 36.5 NA NA NA 36.5 NA ...
##   .. ..$ :'data.frame':	37 obs. of  3 variables:
##   .. .. ..$ date       : chr [1:37] "2020-03-21" "2020-03-28" "2020-04-04" "2020-04-11" ...
##   .. .. ..$ rollingSum : num [1:37] NA 5 7 8 5 3 5 NA NA NA ...
##   .. .. ..$ rollingRate: num [1:37] NA 60.9 85.2 97.4 60.9 36.5 60.9 NA NA NA ...
##   .. ..$ :'data.frame':	37 obs. of  3 variables:
##   .. .. ..$ date       : chr [1:37] "2020-03-21" "2020-03-28" "2020-04-04" "2020-04-11" ...
##   .. .. ..$ rollingSum : num [1:37] NA 4 5 8 6 NA NA NA NA 3 ...
##   .. .. ..$ rollingRate: num [1:37] NA 50.5 63.1 101 75.7 NA NA NA NA 37.9 ...
##   .. ..$ :'data.frame':	37 obs. of  3 variables:
##   .. .. ..$ date       : chr [1:37] "2020-03-21" "2020-03-28" "2020-04-04" "2020-04-11" ...
##   .. .. ..$ rollingSum : num [1:37] 7 6 15 7 4 12 3 5 NA NA ...
##   .. .. ..$ rollingRate: num [1:37] 79.8 68.4 171.1 79.8 45.6 ...
##   .. ..$ :'data.frame':	37 obs. of  3 variables:
##   .. .. ..$ date       : chr [1:37] "2020-03-21" "2020-03-28" "2020-04-04" "2020-04-11" ...
##   .. .. ..$ rollingSum : num [1:37] NA NA 5 3 NA 6 NA NA NA NA ...
##   .. .. ..$ rollingRate: num [1:37] NA NA 48.4 29 NA 58 NA NA NA NA ...
##   .. ..$ :'data.frame':	37 obs. of  3 variables:
##   .. .. ..$ date       : chr [1:37] "2020-03-21" "2020-03-28" "2020-04-04" "2020-04-11" ...
##   .. .. ..$ rollingSum : num [1:37] NA NA 8 3 3 NA 3 NA NA NA ...
##   .. .. ..$ rollingRate: num [1:37] NA NA 98.9 37.1 37.1 NA 37.1 NA NA NA ...
##   .. ..$ :'data.frame':	37 obs. of  3 variables:
##   .. .. ..$ date       : chr [1:37] "2020-03-21" "2020-03-28" "2020-04-04" "2020-04-11" ...
##   .. .. ..$ rollingSum : num [1:37] NA 4 10 4 3 5 NA NA NA NA ...
##   .. .. ..$ rollingRate: num [1:37] NA 43.3 108.4 43.3 32.5 ...
##   .. ..$ :'data.frame':	37 obs. of  3 variables:
##   .. .. ..$ date       : chr [1:37] "2020-03-21" "2020-03-28" "2020-04-04" "2020-04-11" ...
##   .. .. ..$ rollingSum : num [1:37] NA NA 5 11 4 4 5 NA NA NA ...
##   .. .. ..$ rollingRate: num [1:37] NA NA 43.2 95.1 34.6 34.6 43.2 NA NA NA ...
##   .. ..$ :'data.frame':	37 obs. of  3 variables:
##   .. .. ..$ date       : chr [1:37] "2020-03-21" "2020-03-28" "2020-04-04" "2020-04-11" ...
##   .. .. ..$ rollingSum : num [1:37] NA NA 5 4 4 NA 5 NA NA NA ...
##   .. .. ..$ rollingRate: num [1:37] NA NA 45.1 36.1 36.1 NA 45.1 NA NA NA ...
##   .. ..$ :'data.frame':	37 obs. of  3 variables:
##   .. .. ..$ date       : chr [1:37] "2020-03-21" "2020-03-28" "2020-04-04" "2020-04-11" ...
##   .. .. ..$ rollingSum : num [1:37] NA NA NA NA NA NA 5 4 5 NA ...
##   .. .. ..$ rollingRate: num [1:37] NA NA NA NA NA NA 62.2 49.7 62.2 NA ...
##   .. ..$ :'data.frame':	37 obs. of  3 variables:
##   .. .. ..$ date       : chr [1:37] "2020-03-21" "2020-03-28" "2020-04-04" "2020-04-11" ...
##   .. .. ..$ rollingSum : num [1:37] NA NA 3 6 NA NA 3 NA 3 NA ...
##   .. .. ..$ rollingRate: num [1:37] NA NA 41.2 82.4 NA NA 41.2 NA 41.2 NA ...
##   .. ..$ :'data.frame':	37 obs. of  3 variables:
##   .. .. ..$ date       : chr [1:37] "2020-03-21" "2020-03-28" "2020-04-04" "2020-04-11" ...
##   .. .. ..$ rollingSum : num [1:37] NA NA 3 5 4 NA 3 NA NA NA ...
##   .. .. ..$ rollingRate: num [1:37] NA NA 37.3 62.2 49.8 NA 37.3 NA NA NA ...
##   .. ..$ :'data.frame':	37 obs. of  3 variables:
##   .. .. ..$ date       : chr [1:37] "2020-03-21" "2020-03-28" "2020-04-04" "2020-04-11" ...
##   .. .. ..$ rollingSum : num [1:37] NA 4 4 NA 3 NA NA NA 4 NA ...
##   .. .. ..$ rollingRate: num [1:37] NA 51.3 51.3 NA 38.5 NA NA NA 51.3 NA ...
##   .. ..$ :'data.frame':	37 obs. of  3 variables:
##   .. .. ..$ date       : chr [1:37] "2020-03-21" "2020-03-28" "2020-04-04" "2020-04-11" ...
##   .. .. ..$ rollingSum : num [1:37] NA NA 6 8 11 16 4 NA NA NA ...
##   .. .. ..$ rollingRate: num [1:37] NA NA 76.9 102.5 141 ...
##   .. ..$ :'data.frame':	37 obs. of  3 variables:
##   .. .. ..$ date       : chr [1:37] "2020-03-21" "2020-03-28" "2020-04-04" "2020-04-11" ...
##   .. .. ..$ rollingSum : num [1:37] NA 5 8 6 6 7 14 6 NA 3 ...
##   .. .. ..$ rollingRate: num [1:37] NA 52.7 84.4 63.3 63.3 ...
##   .. ..$ :'data.frame':	37 obs. of  3 variables:
##   .. .. ..$ date       : chr [1:37] "2020-03-21" "2020-03-28" "2020-04-04" "2020-04-11" ...
##   .. .. ..$ rollingSum : num [1:37] 4 9 9 11 4 7 5 4 4 6 ...
##   .. .. ..$ rollingRate: num [1:37] 40.1 90.2 90.2 110.3 40.1 ...
##   .. ..$ :'data.frame':	37 obs. of  3 variables:
##   .. .. ..$ date       : chr [1:37] "2020-03-21" "2020-03-28" "2020-04-04" "2020-04-11" ...
##   .. .. ..$ rollingSum : num [1:37] NA 5 8 7 3 NA NA 4 NA NA ...
##   .. .. ..$ rollingRate: num [1:37] NA 73.7 117.9 103.2 44.2 ...
##   .. ..$ :'data.frame':	37 obs. of  3 variables:
##   .. .. ..$ date       : chr [1:37] "2020-03-21" "2020-03-28" "2020-04-04" "2020-04-11" ...
##   .. .. ..$ rollingSum : num [1:37] 4 6 18 11 4 10 NA 3 NA 3 ...
##   .. .. ..$ rollingRate: num [1:37] 36.2 54.3 162.8 99.5 36.2 ...
##   .. ..$ :'data.frame':	37 obs. of  3 variables:
##   .. .. ..$ date       : chr [1:37] "2020-03-21" "2020-03-28" "2020-04-04" "2020-04-11" ...
##   .. .. ..$ rollingSum : num [1:37] NA 5 10 10 NA 6 5 4 NA NA ...
##   .. .. ..$ rollingRate: num [1:37] NA 53.9 107.8 107.8 NA ...
##   .. ..$ :'data.frame':	37 obs. of  3 variables:
##   .. .. ..$ date       : chr [1:37] "2020-03-21" "2020-03-28" "2020-04-04" "2020-04-11" ...
##   .. .. ..$ rollingSum : num [1:37] 4 6 NA 10 3 5 5 NA 5 NA ...
##   .. .. ..$ rollingRate: num [1:37] 40.4 60.6 NA 101.1 30.3 ...
##   .. ..$ :'data.frame':	37 obs. of  3 variables:
##   .. .. ..$ date       : chr [1:37] "2020-03-21" "2020-03-28" "2020-04-04" "2020-04-11" ...
##   .. .. ..$ rollingSum : num [1:37] 3 3 NA 6 NA NA 3 NA NA NA ...
##   .. .. ..$ rollingRate: num [1:37] 40.2 40.2 NA 80.5 NA NA 40.2 NA NA NA ...
##   .. ..$ :'data.frame':	37 obs. of  3 variables:
##   .. .. ..$ date       : chr [1:37] "2020-03-21" "2020-03-28" "2020-04-04" "2020-04-11" ...
##   .. .. ..$ rollingSum : num [1:37] 3 6 6 3 4 3 NA NA NA NA ...
##   .. .. ..$ rollingRate: num [1:37] 33.2 66.5 66.5 33.2 44.3 33.2 NA NA NA NA ...
##   .. ..$ :'data.frame':	37 obs. of  3 variables:
##   .. .. ..$ date       : chr [1:37] "2020-03-21" "2020-03-28" "2020-04-04" "2020-04-11" ...
##   .. .. ..$ rollingSum : num [1:37] 5 7 10 6 8 3 NA 7 NA NA ...
##   .. .. ..$ rollingRate: num [1:37] 59.9 83.9 119.8 71.9 95.8 ...
##   .. ..$ :'data.frame':	37 obs. of  3 variables:
##   .. .. ..$ date       : chr [1:37] "2020-03-21" "2020-03-28" "2020-04-04" "2020-04-11" ...
##   .. .. ..$ rollingSum : num [1:37] 5 4 3 NA NA NA 5 NA NA NA ...
##   .. .. ..$ rollingRate: num [1:37] 56.4 45.1 33.8 NA NA NA 56.4 NA NA NA ...
##   .. ..$ :'data.frame':	37 obs. of  3 variables:
##   .. .. ..$ date       : chr [1:37] "2020-03-21" "2020-03-28" "2020-04-04" "2020-04-11" ...
##   .. .. ..$ rollingSum : num [1:37] 5 14 10 15 16 10 NA 5 5 NA ...
##   .. .. ..$ rollingRate: num [1:37] 57.3 160.5 114.6 171.9 183.4 ...
##   .. ..$ :'data.frame':	37 obs. of  3 variables:
##   .. .. ..$ date       : chr [1:37] "2020-03-21" "2020-03-28" "2020-04-04" "2020-04-11" ...
##   .. .. ..$ rollingSum : num [1:37] 5 13 19 6 15 NA 4 4 NA NA ...
##   .. .. ..$ rollingRate: num [1:37] 52.3 136 198.7 62.7 156.9 ...
##   .. .. [list output truncated]
names(covid_uk$data)
## [1] "areaType"              "areaCode"              "areaName"             
## [4] "length"                "newCasesByPublishDate"

Note that the covid_uk$data is a data frame with a list newCasesByPublishDate inside as its element.

Ouch! 😳 JSON files are not very neat 😱 They are more than often nested, chained -> you’ve got it: Very Messy! 😫 So, we will leave it there. 😬 If you do need to learn more about reading JSON files in R you can explore the functionality of the jsonlite package further by reading Getting started with JSON and jsonlite. The blog post Working with JSON data in very simple way by Kan Nishida provides a great example of how this data format can be used in R.

Other data formats

To speed up the reading process of txt, csv data files you can use the data.table::fread() function. You should only pass to the function the name of the data file you want to import, and fread() will try to work out the appropriate data structure. Check out this blog post Getting Data From An Online Source for some more ideas.

You can use R with appropriate packages to access other data formats. The haven package provides functions for importing SAS, SPSS and Stata file formats or you can use the foreign package for MiniTab portable worksheet data files. Try to look through the help section of the packages you’ve been introduced to and discover other options.

YOUR TURN 👇

1) See if you can find data from https://data.gov.uk/ about a topic you’re interested in.

2) Have a look at this data set: General Election Results 2010. Think about the questions you can answer based on this data.


Material is released under a Creative Commons Attribution-ShareAlike 4.0 International License.