我是R的新手,在设置功能时遇到了一些麻烦。我正试图在大量资产或市场中进行回溯测试。所有这些数据都是CSV格式。
我有一个数据框,基本上是我想在我的环境中打开的市场[资产]及其特征[资产列表]的列表,以便我可以用来测试。我需要经常打开它们,因为它们每天都会更新为CSV文件。
我的主要目标是获取每日下载的CSV文件并将其转换为R中的数据框。
我尝试设置下面的功能,我确实在我的控制台上打印出来,但市场[资产]没有出现在我的环境中。
# this is the function I set up to upload the asset list with the markets and their features/characteristics and in the loop I go through each of their files.
trading.opencsv <- function(rd){
asset.directory <- paste(rd, "list.csv", sep="")
assetlist <<- read.csv(asset.directory, stringsAsFactors=FALSE)
print(assetlist$Market)
for (i in 1:nrow(assetlist)){
asset <- assetlist$Market[i]
x.dir <- paste(rd, asset, ".csv", sep="")
x <- read.csv(x.dir)
print(asset)
assign(asset, x)
}
}
#this is the directory I use to save the csv files and running the function.
rd <- "C:/Users/augus/Dropbox/Trading/R/Trading/Dados/"
trading.opencsv(rd)
答案 0 :(得分:0)
library(dplyr)
library(readr)
library(purrr)
trading.opencsv <- function(rd) {
asset.directory <- paste0(rd, "list.csv")
assetlist <- read_csv(asset.directory)
print(assetlist$Market)
map(assetlist$Market, ~ read_csv(paste0(rd, .x, ".csv"))) %>%
bind_rows()
}