2015-06-19 56 views
0

我有data.frame CLI_CAP_X_PROD_AG的名稱的文本/ HTML文件的名稱:定義像R A data.frame

 FAMILIA_PRD NUM_CLI CAPITAL_SOL PART_CAP_PER ATRASADA ATR_PER 
     A    536  2616925  33.62 467830 17.88 
     B    151  1613035  20.72 268223 16.63 

,當我嘗試使用數據的名稱保存文件.frame我得到錯誤:

 print(temp,type = "html", include.rownames = FALSE, file = paste(CLI_CAP_X_PROD_AG,"_tab.html", sep="")) 

因爲R讀取了CLI_CAP_X_PROD_AG的元素。

任何幫助將不勝感激!

+0

難道你不需要把它放在一個字符串「CLI_CAP_X_PROD_AG」嗎? – sunny

+0

這是什麼'print()'函數,顯然需要'type'和'file'參數? ['print()'](https://stat.ethz.ch/R-manual/R-devel/library/base/html/print.html)沒有這樣的參數,['print.default() '](https://stat.ethz.ch/R-manual/R-devel/library/base/html/print.default.html)和['print.data.frame()'](https:/ /stat.ethz.ch/R-manual/R-devel/library/base/html/print.dataframe.html)。 – bgoldst

+0

這是一個函數從xtable – JVALLEJO

回答

0

你應該將你的xtables存儲在一個已命名的列表中並遍歷列表。演示:

library('xtable'); 
li <- list(t1=xtable(data.frame(a=letters[1:3],b=1:3)),t2=xtable(data.frame(a=letters[4:6],b=4:6))); 
names(li); 
## [1] "t1" "t2" 
li; 
## $t1 
## % latex table generated in R 3.1.3 by xtable 1.7-4 package 
## % Fri Jun 19 13:48:30 2015 
## \begin{table}[ht] 
## \centering 
## \begin{tabular}{rlr} 
## \hline 
## & a & b \\ 
## \hline 
## 1 & a & 1 \\ 
## 2 & b & 2 \\ 
## 3 & c & 3 \\ 
## \hline 
## \end{tabular} 
## \end{table} 
## 
## $t2 
## % latex table generated in R 3.1.3 by xtable 1.7-4 package 
## % Fri Jun 19 13:48:30 2015 
## \begin{table}[ht] 
## \centering 
## \begin{tabular}{rlr} 
## \hline 
## & a & b \\ 
## \hline 
## 1 & d & 4 \\ 
## 2 & e & 5 \\ 
## 3 & f & 6 \\ 
## \hline 
## \end{tabular} 
## \end{table} 
## 
for (n in names(li)) print(li[[n]],type='html',include.rownames=F,file=paste0(n,'_tab.html')); 
file.show('t1_tab.html',pager='cat'); 
## <!-- html table generated in R 3.1.3 by xtable 1.7-4 package --> 
## <!-- Fri Jun 19 13:48:34 2015 --> 
## <table border=1> 
## <tr> <th> a </th> <th> b </th> </tr> 
## <tr> <td> a </td> <td align="right"> 1 </td> </tr> 
## <tr> <td> b </td> <td align="right"> 2 </td> </tr> 
## <tr> <td> c </td> <td align="right"> 3 </td> </tr> 
## </table> 
## 
file.show('t2_tab.html',pager='cat'); 
## <!-- html table generated in R 3.1.3 by xtable 1.7-4 package --> 
## <!-- Fri Jun 19 13:48:34 2015 --> 
## <table border=1> 
## <tr> <th> a </th> <th> b </th> </tr> 
## <tr> <td> d </td> <td align="right"> 4 </td> </tr> 
## <tr> <td> e </td> <td align="right"> 5 </td> </tr> 
## <tr> <td> f </td> <td align="right"> 6 </td> </tr> 
## </table> 
## 
+0

謝謝你爲我工作。儘管我找到了另一種解決方案。 – JVALLEJO