20.6 Reading part of a sheet

This spreadsheet is one of the example spreadsheets provided in the readxl package. We can use the readxl_example() function to locate the spreadsheet on your system in the directory where the package is installed.

deaths_path <- readxl_example("deaths.xlsx")

deaths <- read_excel(deaths_path)
## New names:
## • `` -> `...2`
## • `` -> `...3`
## • `` -> `...4`
## • `` -> `...5`
## • `` -> `...6`
deaths
## # A tibble: 18 × 6
##    `Lots of people`             ...2                     ...3  ...4  ...5  ...6 
##    <chr>                        <chr>                    <chr> <chr> <chr> <chr>
##  1 simply cannot resist writing <NA>                     <NA>  <NA>  <NA>  some…
##  2 at                           the                      top   <NA>  of    thei…
##  3 or                           merging                  <NA>  <NA>  <NA>  cells
##  4 Name                         Profession               Age   Has … Date… Date…
##  5 David Bowie                  musician                 69    TRUE  17175 42379
##  6 Carrie Fisher                actor                    60    TRUE  20749 42731
##  7 Chuck Berry                  musician                 90    TRUE  9788  42812
##  8 Bill Paxton                  actor                    61    TRUE  20226 42791
##  9 Prince                       musician                 57    TRUE  21343 42481
## 10 Alan Rickman                 actor                    69    FALSE 16854 42383
## 11 Florence Henderson           actor                    82    TRUE  12464 42698
## 12 Harper Lee                   author                   89    FALSE 9615  42419
## 13 Zsa Zsa Gábor                actor                    99    TRUE  6247  42722
## 14 George Michael               musician                 53    FALSE 23187 42729
## 15 Some                         <NA>                     <NA>  <NA>  <NA>  <NA> 
## 16 <NA>                         also like to write stuff <NA>  <NA>  <NA>  <NA> 
## 17 <NA>                         <NA>                     at t… bott… <NA>  <NA> 
## 18 <NA>                         <NA>                     <NA>  <NA>  <NA>  too!

Here the data we want to read in starts in cell A5 and ends in cell F15. In spreadsheet notation, this is A5:F15, which we supply to the range argument:

read_excel(deaths_path, range = "A5:F15")
## # A tibble: 10 × 6
##    Name      Profession   Age `Has kids` `Date of birth`     `Date of death`    
##    <chr>     <chr>      <dbl> <lgl>      <dttm>              <dttm>             
##  1 David Bo… musician      69 TRUE       1947-01-08 00:00:00 2016-01-10 00:00:00
##  2 Carrie F… actor         60 TRUE       1956-10-21 00:00:00 2016-12-27 00:00:00
##  3 Chuck Be… musician      90 TRUE       1926-10-18 00:00:00 2017-03-18 00:00:00
##  4 Bill Pax… actor         61 TRUE       1955-05-17 00:00:00 2017-02-25 00:00:00
##  5 Prince    musician      57 TRUE       1958-06-07 00:00:00 2016-04-21 00:00:00
##  6 Alan Ric… actor         69 FALSE      1946-02-21 00:00:00 2016-01-14 00:00:00
##  7 Florence… actor         82 TRUE       1934-02-14 00:00:00 2016-11-24 00:00:00
##  8 Harper L… author        89 FALSE      1926-04-28 00:00:00 2016-02-19 00:00:00
##  9 Zsa Zsa … actor         99 TRUE       1917-02-06 00:00:00 2016-12-18 00:00:00
## 10 George M… musician      53 FALSE      1963-06-25 00:00:00 2016-12-25 00:00:00