R - 如何从文件夹中读取多个文件,将它们转换为 xts 并对它们进行一些数据分析?

R - How to read multiple files from a folder, convert them in xts and do some data analysis on them?

我有一个包含 199 个文件的文件夹(从 blah-001-a.expblah-199-a.exp

我想为每个文件做这样的事情:

DF<- read.csv("D:/ebook/myfolder/blah-001-a.exp", sep=";")
xts<-xts(x=DF[,-c(1,13)], order.by = as.Date(x=DF$DATA,format="%d.%m.%Y"))
#other codes and report pdf file...

我尝试了一些这样的代码,但它只读取文件而没有将它们转换为 xts:

folder <- "D:/ebook/myfolder/"    
filenames <- list.files(path=folder) 
for (i in 1:length(filenames)){
      assign(filenames[i], 
             read.csv(paste0(folder, filenames[i]),sep=';')
      )}

你能给我一些建议吗? 提前致谢。

do.stuff <- function(file_in){
    DF <- read.csv(file_in, sep=";")
    xts <-xts(x=DF[,-c(1,13)], order.by =as.Date(x=DF$DATA,format="%d.%m.%Y"))
}
the_files <- list.files('path/to/files',full.names = T)
the_stuff <- lapply(1:length(the_files),function(i)do.stuff(the_files[[i]]))
names(the_stuff) <- basename(the_files)