Previous chapter
Read Excel FilesRead Excel Files using readxl
Next chapter

readxl

From readxl.tidyverse.org:

The readxl package makes it easy to get data out of Excel and into R. Compared to many of the existing packages (e.g. gdata, xlsx, xlsReadWrite) readxl has no external dependencies, so it’s easy to install and use on all operating systems. It is designed to work with tabular data.

readxl supports both the legacy .xls format and the modern xml-based .xlsx format. The libxls C library is used to support .xls, which abstracts away many of the complexities of the underlying binary format. To parse .xlsx, we use the RapidXML C++ library.

Use read_excel workhorse function:

read_excel(path = "<filename.xlsx>", sheet = "<sheetname>", 
           range = "A1:D87", ...)

From https://readxl.tidyverse.org

Exercise: Read Single File and Compare

In the workspace: Try to read the ‘mtcars’ sheet from data/data-sources-04.xlsx into an R data.frame using the read_excel() function from the package readxl. Compare the resulting data set with the existing mtcars dataset. Compare the two data sets using the all.equal() function.

Exercise: Read Euro Cross Rates

In the workspace: Try to read the ‘euro.cross’ sheet from data/data-sources-04.xlsx into an R data.frame using readxl.

Use the range parameter to read only Austrian Schilling (ATS) rates (first row including headers without CCY column).

Exercise: Performance of Stocks Daimler - BMW

  1. Read the sheet ‘dai_bmw’ from data/data-sources-04.xlsx using readxl.
  1. Calculate the 17-Year stock price performance of both stocks from 2000-10-20 until 2017-10-20 in percent.
  1. Calculate the 17-Year stock price performance of Daimler from 2000-10-20 until 2017-10-20 (without Dividends) in USD. Read the EUR/USD foreign exchange data from the sheet eurusd.