[R-br] Saída Html do pacote Gmisc
Abel Brasil Ramos da Silva
abelbrasil88 em gmail.com
Quarta Setembro 20 21:03:47 -03 2017
Olá à todos, Boa Noite!
Estou tentando reproduzir o seguinte código abaixo para gerar uma tabela
Html na aba do Viewer:
data(mtcars)
library(Hmisc)
label(mtcars$mpg) <- "Gas"
units(mtcars$mpg) <- "Miles/(US) gallon"
label(mtcars$wt) <- "Weight"
units(mtcars$wt) <- "10<sup>3</sup> kg" # not sure the unit is correct
mtcars$am <- factor(mtcars$am, levels=0:1, labels=c("Automatic", "Manual"))
label(mtcars$am) <- "Transmission"
mtcars$gear <- factor(mtcars$gear)
label(mtcars$gear) <- "Gears"
mtcars$col <- factor(sample(c("red", "black", "silver"),
size=NROW(mtcars), replace=TRUE))
label(mtcars$col) <- "Car color"
library(Gmisc)
getTable1Stats <- function(x, digits = 0, ...){
getDescriptionStatsBy(x = x,
by = mtcars$am,
digits = digits,
continuous_fn = describeMedian,
header_count = TRUE,
...)}
t1 <- list()
t1[["Gas"]] <-
getTable1Stats(mtcars$mpg)
t1[["Weight†"]] <-
getTable1Stats(mtcars$wt)
t1[["Color"]] <-
getTable1Stats(mtcars$col)
# If we want to use the labels set in the beginning
# we add an element without a name
t1 <- c(t1,
list(getTable1Stats(mtcars$gear)))
mergeDesc(t1,
htmlTable_args = list(css.rgroup = "",
caption = "Basic descriptive statistics
from the mtcars dataset",
tfoot = "† The weight is in
10<sup>3</sup> kg"))
*PORÉM, AO INVÉS DO OUTPUT SAIR NO VIEWER EM FORMA DE TABELA O MESMO PRODUZ
A SAÍDA ABAIXO:*
<table class='gmisc_table' style='border-collapse: collapse; margin-top:
1em; margin-bottom: 1em;' >
<thead>
<tr><td colspan='3' style='text-align: left;'>
Basic descriptive statistics from the mtcars dataset</td></tr>
<tr>
<th style='border-bottom: 1px solid grey; border-top: 2px solid grey;'>
</th>
<th style='border-bottom: 1px solid grey; border-top: 2px solid grey;
text-align: center;'>Automatic<br />
No. 19</th>
<th style='border-bottom: 1px solid grey; border-top: 2px solid grey;
text-align: center;'>Manual<br />
No. 13</th>
</tr>
</thead>
<tbody>
<tr>
<td style='text-align: left;'>Gas</td>
<td style='text-align: center;'>17 (15 - 19)</td>
<td style='text-align: center;'>23 (21 - 30)</td>
</tr>
<tr>
<td style='text-align: left;'>Weight†</td>
<td style='text-align: center;'>4 (3 - 4)</td>
<td style='text-align: center;'>2 (2 - 3)</td>
</tr>
<tr><td colspan='3' style=''>Color</td></tr>
<tr>
<td style='text-align: left;'> black</td>
<td style='text-align: center;'>11 (58%)</td>
<td style='text-align: center;'>5 (38%)</td>
</tr>
<tr>
<td style='text-align: left;'> red</td>
<td style='text-align: center;'>6 (32%)</td>
<td style='text-align: center;'>6 (46%)</td>
</tr>
<tr>
<td style='text-align: left;'> silver</td>
<td style='text-align: center;'>2 (11%)</td>
<td style='text-align: center;'>2 (15%)</td>
</tr>
<tr><td colspan='3' style=''>Gears</td></tr>
<tr>
<td style='text-align: left;'> 3</td>
<td style='text-align: center;'>15 (79%)</td>
<td style='text-align: center;'>0 (0%)</td>
</tr>
<tr>
<td style='text-align: left;'> 4</td>
<td style='text-align: center;'>4 (21%)</td>
<td style='text-align: center;'>8 (62%)</td>
</tr>
<tr>
<td style='border-bottom: 2px solid grey; text-align:
left;'> 5</td>
<td style='border-bottom: 2px solid grey; text-align: center;'>0 (0%)</td>
<td style='border-bottom: 2px solid grey; text-align: center;'>5 (38%)</td>
</tr>
</tbody>
<tfoot><tr><td colspan='3'>
† The weight is in 10<sup>3</sup> kg</td></tr></tfoot>
</table>
Gostaria de saber como faço para que o output seja reproduzido no Viewer?
Agradeço à ajuda!
-------------- Próxima Parte ----------
Um anexo em HTML foi limpo...
URL: <http://listas.inf.ufpr.br/pipermail/r-br/attachments/20170920/396ca77c/attachment.html>
Mais detalhes sobre a lista de discussão R-br