Hi - I would like to create a nicer table with this code- than just the output from summarize. Any advice?
baro_unweightedpointcoverage <- df_child_level_baro_point_coverage %>%
as_survey_design(ids=grappe_no,) cluster number
baro_unweightedpointcoverage %>%
group_by(covered) %>%
summarize(proportion=survey_mean(),
total=survey_total())
You may want to consider the gt
package.
For us to really help, it would be helpful to provide a reproducible example:
FAQ: What's a reproducible example (reprex
) and how do I create one?
Also, you can wrap your text in three back-ticks (```) to format it as code. This makes it a lot easier to read:
baro_unweightedpointcoverage <- df_child_level_baro_point_coverage %>%
as_survey_design(ids=grappe_no,) #cluster number
baro_unweightedpointcoverage %>%
group_by(covered) %>%
summarize(proportion=survey_mean(),
total=survey_total())
How would I store this table in the gt package?
Apologies if I've misunderstood, but when you were talking about getting a "nicer table" I thought you were asking how you could present the data in a nicer way. gt
produces HTML tables, but you can save them as static PNG images too.
As I say, we can't really see what your data output is, but if you provide a reproducible example we can see what your data looks like and better understand what the problem is that you're having:
FAQ: What's a reproducible example ( reprex
) and how do I create one?
Hey Jack - thanks a lot- this is an example of what I'd like to display in an HTML table- just not sure how to print it in Markdown.
my_des %>%
group_by(awards) %>%
summarize(proportion=survey_mean(),
total=survey_total())
#> # A tibble: 2 x 5
#> awards proportion proportion_se total total_se
#> <fct> <dbl> <dbl> <dbl> <dbl>
#> 1 No 0.38 0.0344 2354. 213.
#> 2 Yes 0.62 0.0344 3840. 213.
I see! In that case gt
may be of some use:
library(tidyverse)
library(gt)
df = tribble(
~awards, ~proportion, ~proportion_se, ~total, ~total_se,
"Yes", 0.62, 0.0344, 3840, 213,
"No", 0.38, 0.0344, 2354, 213,
)
gt(df) |>
gt::cols_label(awards = "Award",
proportion = "Mean",
proportion_se = "SE",
total = "Mean",
total_se = "SE") |>
tab_spanner("Proportion", contains("prop")) |>
tab_spanner("Total", contains("total")) |>
fmt_percent(contains("prop"), drop_trailing_zeros = T) |>
cols_width(proportion:total_se ~ px(75))
If you put the above code in an RMarkdown chunk it'll show the gt
HTML table, much in the same way that when you put ggplot2
code in a chunk it'll show the resulting plot.
1 Like
Awesome, you have made my morning!!! Any advice on how to convert the above into a 95% confidence interval?
system
Closed
December 5, 2021, 1:03pm
8
This topic was automatically closed 21 days after the last reply. New replies are no longer allowed. If you have a query related to it or one of the replies, start a new topic and refer back with a link.