file.exists(path)中的错误:R中的'file'参数无效

时间:2015-09-04 10:47:15

标签: r excel file path

请接受我的道歉,因为我是R的新手。以下代码用于一次处理多个文件并将输出放在单独的文件夹中。

require(highfrequency)
 require(quantmod)
 require(readxl)
 input_files1=list("file_path1.xlsx","file_path2.xlsx","file_path3.xlsx")    #making list of file paths

for(i in length(input_files1))

{
    bid_df<-read_excel(input_files1[i], sheet = 1, col_names = TRUE, col_types = NULL, na = "", skip = 0)
#read_excel takes file path as first argument
    ask_df<-read_excel(input_files1[i], sheet = 2, col_names = TRUE, col_types = NULL, na = "", skip = 0)

    trade_df<-read_excel(input_files1[i], sheet = 3, col_names = TRUE, col_types = NULL, na = "", skip = 0)

  qdata_df <- merge(ask_df, bid_df, by = "TIMESTAMP")
  qdata_xts_raw<-xts(qdata_df[,-1], order.by=qdata_df[,1])
  qdata_xts_m<-mergeQuotesSameTimestamp(qdata_xts_raw, selection = "median")
  trade_xts_raw <- xts(trade_df[,-1], order.by=trade_df[,1])
  trade_xts_m<-mergeTradesSameTimestamp(trade_xts_raw, selection = "median")
  tqdata=matchTradesQuotes(trade_xts_m,qdata_xts_m)
  quoted_spread<-tqLiquidity(tqdata,trade_xts_m,qdata_xts_m,type="qs")
  qs_30<-aggregatets(quoted_spread,FUN="mean",on="minutes",k=30)
  indexTZ(qs_30) <- "UTC"

  write.csv(qs_30, file = file.path("output_file_path", paste0("CAN_out",    i)))
  }

运行代码时,会出现以下错误 file.exists(path)中的错误:无效的'file'参数 请帮助您删除错误并运行代码。

1 个答案:

答案 0 :(得分:0)

访问路径中列表的元素作为input_files1 [[i]]