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

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

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:

  1. library(expss)
  2. # bogus example data
  3. 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")
  4. htmlTable(x %>%
  5. tab_cells(visits, months_enrolled) %>%
  6. tab_rows(marital2, Relationship2, total()) %>%
  7. tab_stat_fun(Mean = w_mean, "Valid N" = w_n, method = list) %>%
  8. tab_pivot() %>%
  9. set_caption("Table 6: Bogus Visits and Duration by Characteristics") %>%
  10. htmlTable(., css.cell = c("width: 220px", # first column width
  11. 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:

  1. library(expss)
  2. # bogus example data
  3. 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;)
  4. htmlTable(x %&gt;%
  5. tab_cells(visits,months_enrolled) %&gt;%
  6. tab_rows(marital2, Relationship2, total()) %&gt;% tab_stat_fun(Mean = w_mean, &quot;Valid N&quot; = w_n, method = list) %&gt;%
  7. tab_pivot() %&gt;%
  8. set_caption(&quot;Table 6: Bogus Visits and Duration by Characteristics&quot;) %&gt;%
  9. htmlTable(.,css.cell = c(&quot;width: 220px&quot;, # first column width
  10. 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:

  1. htmlTable(x %&gt;%
  2. tab_cells(visits, months_enrolled) %&gt;%
  3. tab_cols(marital2, Relationship2, total()) %&gt;%
  4. tab_rows(total(label = &quot;|&quot;)) %&gt;%
  5. tab_stat_fun(Mean = w_mean, &quot;Valid N&quot; = w_n) %&gt;%
  6. tab_pivot() %&gt;%
  7. tab_transpose() %&gt;%
  8. set_caption(&quot;Table 6: Bogus Visits and Duration by Characteristics&quot;) %&gt;%
  9. htmlTable(.,css.cell = c(&quot;width: 220px&quot;, # first column width
  10. 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:

确定