2016-10-22 58 views
1

我有以下代碼和print.xtableFtable忽略乳膠的附加選項。爲什麼R函數print.xtableFtable忽略我的選項?

##### Contingency tables - 34Y 
library(xtable) 
B <- ftable(prereg34Y_sub$employmentStatus34Y, prereg34Y_sub$ethnicity34Y, dnn=c("Unemployed", "NonBritish")) 
sink("CTFemaleNonBrit34Y.tex", type="output") 
print.xtableFtable(xtableFtable(B, method = "compact"), table.placement = "h!") 
sink() 

的輸出是:

% latex table generated in R 3.3.1 by xtable 1.8-2 package 
% Sat Oct 22 18:08:35 2016 
\begin{table}[ht] 
\centering 
\begin{tabular}{l |rr} 
\hline 
Unemployed $\vert$ NonBritish & \multicolumn{1}{l}{ 0} & \multicolumn{1}{l}{ 1} \\ 
\hline 
0        & 2065 & 68 \\ 
1        & 31 & 2 \\ 
\hline 
\end{tabular} 
\end{table} 

表中的位置被HT代替ħ!有沒有人有一個想法,爲什麼?

回答

1

它似乎並不該table.placement論證會從print.xtableFtableprint.xtable傳承下去,但你可以在全局options(xtable.table.placement = "h!")設置可選運行print(xtableFtable(B))

library(xtable) 

# table.placement doesnt seem to work 
B <- ftable(mtcars$am, mtcars$cyl, dnn=c("Unemployed", "NonBritish")) 
print(xtableFtable(B), table.placement = "h!")  
# % latex table generated in R 3.3.1 by xtable 1.8-2 package 
# % Sat Oct 22 18:00:52 2016 
# \begin{table}[ht] 
# --- 
# --- 

# But works for other data types 
B2 <- table(mtcars$am, mtcars$cyl, dnn=c("Unemployed", "NonBritish")) 
print(xtable(B2), table.placement = "h!") 
# % latex table generated in R 3.3.1 by xtable 1.8-2 package 
# % Sat Oct 22 18:00:52 2016 
# \begin{table}[h!] 
# --- 
# --- 

所以設置選項全球

options(xtable.table.placement = "h!") 
print(xtableFtable(B)) 
# % latex table generated in R 3.3.1 by xtable 1.8-2 package 
# % Sat Oct 22 18:00:52 2016 
# \begin{table}[h!] 
# --- 
# --- 
+0

它現在有效。我今天學到了一些新東西:全球設置選項。 – FarFarAway

+1

非常感謝! – FarFarAway

+0

非常歡迎 – user20650

相關問題