R块中导入数据

问题描述 投票:0回答:1

我尝试将大量数据导入R。导入R 15分钟后,R崩溃了。

因此,我需要将数据导入分成多个间隔。以下是我如何在101-200间隔内调用列表ALL200的方法进行此操作。

但是,我不确定如何自动执行此操作,因为我每次都需要将间隔设置为下一个100?

 ALL200 <- list() # creates a list
    listcsv <- dir(pattern = "*.csv") # creates the list of all the csv files in the directory
    #make a list in R with all the stocks
    for (k in 101:200){
      ALL200[[k]] <- read_csv(listcsv[k], 
                               col_types = cols(expirDate = col_date(format = "%Y-%m-%d"), 
                                                                    trade_date = col_date(format = "%Y-%m-%d")))

希望您能帮助我。

r import intervals
1个回答
0
投票

我不确定这是否可以解决您的问题,但请尝试使用列表列表:

A <- list()

listcsv <- dir(pattern = "*.csv")

for (i in 1:10) {
    B <- list()
    for (k in ( (i*100 + 1):((i+1)*100)){
      B[[k]] <- read_csv(listcsv[k], 
                         col_types = cols(expirDate = col_date(format = "%Y-%m-%d"),
                         trade_date = col_date(format = "%Y-%m-%d")))
    }
    A[[i]] <- B
}
© www.soinside.com 2019 - 2024. All rights reserved.