[R] How to import an excel data file

Rainer Hurling rhur||n @end|ng |rom gwdg@de
Sun Sep 24 11:25:30 CEST 2023


Dear David,

Am 23.09.23 um 01:10 schrieb Parkhurst, David:
> I know I should save it as a .csv file, which I have done.
> I�m told I should use the read_excel() function from the readxl package.
> My question is, how do I express the location of the file.  The file is named KurtzData.csv.
> Its location in my Mac files is DFPfiles/ae/FriendsMonroe/KurtzData.csv
> How exactly---What �, etc.---do I type with its name in the read_excel() function?
> It�s been a long time since I�ve used R.
> Thanks for any help.
> 
> 
> 	[[alternative HTML version deleted]]

Even though there are already some answers, I would like to comment on 
the question.

The advice to export the excel data to a csv file to import it 
afterwards from the readxl package into R using read_excel() is a bit 
around the corner. Instead, the readxl package can better read the Excel 
format directly, both the one as .xls format and the new .xlsx format.

I am basically a proponent for reading original data (here Excel) 
directly and not via an intermediate format like csv. This avoids, among 
other things, that subsequently supplemented or corrected original Excel 
data are not converted to csv by mistake and are thus not available the 
next time they are imported into R.

In order to take the path to the data into account when reading it with 
read_excel(), you can proceed as follows (analogous if your path is 
relativ to your R working directory), for example:

Kurtz <- readxl::read_excel(path = 
'/DFPfiles/ae/FriendsMonroe/KurtzData.xlsx', sheet = 
'name-or-number-of-the-sheet')


Additional parameters may be necessary, e.g. to specify whether to skip 
headers when reading the Excel data. The help page for the function 
gives valuable hints here:

?readxl::read_excel


Besides the R package readxl I have also had very good experiences 
reading and writing Excel files with the package openxlsx ;)

HTH,
Rainer Hurling



More information about the R-help mailing list