TLDR: how to take the nth element from a list to use it as an input for a function.
I get three different excel files in my mail every day: Ayyyymmdd.xls
, Byyyymmdd.xls
and Cyyyymmdd.xls
(the file names change every day; "yyyy" is year, "mm" is month and "dd" is day) .
I need to read these files in R. To do this, I created a list that changes according to today's date. Today, the list looks as follows:
files <- as.list(c("A20180829.xls", "B20180829.xls", "C20180829.xls")
I now need to read all three files separately (using lapply
works, but I want to reference only one element at a time). Unfortunately, the following command doesn't work:
Atoday <- read.xls(files[1], sheet = 1) # Doesn't work
Atoday <- read.xls("A20180829.xls", sheet = 1) # Works
My main concern is how to take the nth element from a list to use it as an input for a function. The function doesn't need to be read.xls
, for all I care, it could be read.csv()
, fread()
, etc.