我是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)