Sure, here’s the translation: 如何进一步优化expss表格格式?

huangapple go评论76阅读模式
英文:

how to further refine expss table format?

问题

I am trying to improve my table design using expss. My current design is shown below using the following code:

library(expss)
# bogus example data
x <- structure(list(visits = structure(c(17, 2, 23, 1, 21), label = "Total # Home Visits", class = c("labelled", "numeric")), months_enrolled = structure(c(21.42474, 51.105, 52.474, 53.75, 60.0392105), label = "Enrollment Duration (months)", class = c("labelled","numeric")), marital2 = structure(c("Married", NA, "Married", "Married", "Married"), label = "Marital Status", class = c("labelled", "character")), Relationship2 = structure(c("Mother", "Mother", "Mother", "Mother", "Mother"), label = "Relationship (recoded)", class = c("labelled", "character"))), row.names = c(NA, 5L), class = "data.frame")

htmlTable(x %>% 
tab_cells(visits, months_enrolled) %>%
tab_rows(marital2, Relationship2, total()) %>%
tab_stat_fun(Mean = w_mean, "Valid N" = w_n, method = list) %>%
tab_pivot() %>%
set_caption("Table 6: Bogus Visits and Duration by Characteristics") %>%
htmlTable(., css.cell = c("width: 220px", # first column width
rep("width: 50px", ncol(.) - 1))))

I'd like to improve the table design by placing the mean statistics for Home Visits and Enrollment Duration as columns, thus saving a row for each level of Marital Status (and other vars in tab_rows). How is this achieved? Also, is it possible to shade alternate rows?

英文:

I am trying to improve my table design using expss. My current design is shown below using the following code:

library(expss)
# bogus example data
x&lt;-structure(list(visits= structure(c(17, 2, 23, 1, 21), label = &quot;Total # Home Visits&quot;, class = c(&quot;labelled&quot;, &quot;numeric&quot;)), months_enrolled = structure(c(21.42474, 51.105, 52.474, 53.75, 60.0392105), label = &quot;Enrollment Duration (months)&quot;, class =c(&quot;labelled&quot;,&quot;numeric&quot;)), marital2 = structure(c(&quot;Married&quot;, NA, &quot;Married&quot;, &quot;Married&quot;, &quot;Married&quot;), label = &quot;Marital Status&quot;, class = c(&quot;labelled&quot;, &quot;character&quot;)), Relationship2 = structure(c(&quot;Mother&quot;, &quot;Mother&quot;, &quot;Mother&quot;, &quot;Mother&quot;, &quot;Mother&quot;), label = &quot;Relationship (recoded)&quot;, class = c(&quot;labelled&quot;, &quot;character&quot;))), row.names = c(NA, 5L), class = &quot;data.frame&quot;)

htmlTable(x %&gt;% 
tab_cells(visits,months_enrolled) %&gt;%
tab_rows(marital2, Relationship2,  total()) %&gt;%     tab_stat_fun(Mean = w_mean, &quot;Valid N&quot; = w_n, method = list) %&gt;%
tab_pivot() %&gt;%
set_caption(&quot;Table 6: Bogus Visits and Duration by Characteristics&quot;) %&gt;% 
htmlTable(.,css.cell = c(&quot;width: 220px&quot;, # first column width
                          rep(&quot;width: 50px&quot;, ncol(.) - 1))))

I'd like to improve the table design by placing the mean statistics for Home Visits and Enrollment Duration as columns, thus saving a row for each level of Marital Status (and other vars in tab_rows). How is this achieved? Also, is it possible to shade alternate rows?

Sure, here’s the translation:
如何进一步优化expss表格格式?

答案1

得分: 1

以下是代码中需要翻译的部分:

"It seems, the simplest way is to transpose table:"
"Table 6: Bogus Visits and Duration by Characteristics"

英文:

It seems, the simplest way is to transpose table:

htmlTable(x %&gt;% 
              tab_cells(visits, months_enrolled) %&gt;%
              tab_cols(marital2, Relationship2,  total()) %&gt;%  
              tab_rows(total(label = &quot;|&quot;)) %&gt;% 
              tab_stat_fun(Mean = w_mean, &quot;Valid N&quot; = w_n) %&gt;%
              tab_pivot() %&gt;%
              tab_transpose() %&gt;% 
              set_caption(&quot;Table 6: Bogus Visits and Duration by Characteristics&quot;) %&gt;% 
              htmlTable(.,css.cell = c(&quot;width: 220px&quot;, # first column width
                                       rep(&quot;width: 50px&quot;, ncol(.) - 1))))

Sure, here’s the translation:
如何进一步优化expss表格格式?

huangapple
  • 本文由 发表于 2020年1月4日 00:44:42
  • 转载请务必保留本文链接:https://go.coder-hub.com/59582227.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定