首页 > 解决方案 > R:在函数中指定输出保存名称

问题描述

我试图在我的函数中指定输出文件,这在 R 中可能吗?

X 是我的数据集,例如 Indexreturns$marketreturn 因为 ZI 然后想指定我想如何调用我的输出并将其发送到 tex 文件。

我的功能如下:

ProcessIndexReturns <- function(x,z){
  z <- describe.by(x,group=Indexreturns$group)
  x <- describe(x)
  z <- rbindlist(z)
  z <- rbind(z,x)
  z <- z[c(1,4,5,6,7,8,9,10,11,2,3,12),c(4,3)]
  z <- z %>%
    mutate(Sharpe = (12*mean)/(sqrt(12)*sd)) %>%
    mutate(`Equity Premium `= 12*mean*100) %>%
    mutate(sd = sqrt(12)*sd*100) %>%
    select(-mean)

  z <- z[,c(2,3,1)]
  row.names(z) <- c("1820","1830","1840","1850","1860","1870","1880","1890","1900","1910","1920","Full Sample")
  print(xtable(z, type = "latex"), file = "z.tex")
}

如果我插入 X 和 Z,我想接收一个名为 z 的 data.table 和一个名为“z”.tex 的输出文件

标签: rfunctionoutput

解决方案


推荐阅读