diff --git a/05-descriptive-analysis.Rmd b/05-descriptive-analysis.Rmd index 6604d9b..b247fd6 100644 --- a/05-descriptive-analysis.Rmd +++ b/05-descriptive-analysis.Rmd @@ -449,7 +449,7 @@ recs_des %>% mutate(p = p * 100) ``` -with `r .preg %>% filter(Region=="Northeast") %>% pull(p) %>% signif(3)`% of the households in the Northeast, `r .preg %>% filter(Region=="Midwest") %>% pull(p) %>% signif(3)`% in the Midwest, and so on. Note that the proportions in column `p` add up to one. +`r .preg %>% filter(Region=="Northeast") %>% pull(p) %>% signif(3)`% of the households are in the Northeast, `r .preg %>% filter(Region=="Midwest") %>% pull(p) %>% signif(3)`% are in the Midwest, and so on. Note that the proportions in column `p` add up to one. \index{Categorical data|(} The `survey_prop()` function is essentially the same as using `survey_mean()` with a categorical variable and without specifying a numeric variable in the `x` argument. The following code gives us the same results as above: diff --git a/index.Rmd b/index.Rmd index 2cdcb1b..8f57dec 100644 --- a/index.Rmd +++ b/index.Rmd @@ -23,6 +23,8 @@ header-includes: ```{r setup} #| include: false +knitr::opts_chunk$set(fig.pos = "h!", out.extra = "") + library(styler) options( htmltools.dir.version = FALSE, formatR.indent = 2, digits = 4 @@ -38,9 +40,13 @@ library(prettyunits) book_colors <- c("#0b3954", "#087e8b", "#bfd7ea", "#ff8484", "#8d6b94") as_latex_with_caption <- function(gtobj, chunk_label) { - gt_l <- gt::as_latex(gtobj) + lt <- nrow(gtobj[["_data"]]) >= 10 + gt_l <- gtobj %>% tab_options(latex.use_longtable=lt, latex.tbl.pos="!htb") %>% gt::as_latex() caption <- paste0( - "\\caption{\\label{tab:", chunk_label, "}(ref:", chunk_label, ")}\\\\") + "\\caption{\\label{tab:", chunk_label, "}(ref:", chunk_label, ")}") + if (lt){ + caption <- paste0(caption, " \\\\") + } latex <- strsplit(gt_l[1], split = "\n")[[1]] idxtable <- which(stringr::str_detect(latex, "begin") & stringr::str_detect(latex, "table")) # https://tex.stackexchange.com/questions/95236/as-first-character-in-table-row @@ -139,4 +145,4 @@ if (knitr:::is_html_output()){ } rm(citation_text) -``` \ No newline at end of file +``` diff --git a/renv.lock b/renv.lock index 4ede076..6e9f30a 100644 --- a/renv.lock +++ b/renv.lock @@ -956,9 +956,15 @@ }, "gt": { "Package": "gt", - "Version": "0.10.1", - "Source": "Repository", - "Repository": "CRAN", + "Version": "0.11.0.9000", + "Source": "GitHub", + "RemoteType": "github", + "RemoteHost": "api.github.com", + "RemoteRepo": "gt", + "RemoteUsername": "rstudio", + "RemotePkgRef": "rstudio/gt", + "RemoteRef": "HEAD", + "RemoteSha": "28de628ac53ecded0f747396333507477f537923", "Requirements": [ "R", "base64enc", @@ -982,7 +988,7 @@ "vctrs", "xml2" ], - "Hash": "03009c105dfae79460b8eb9d8cf791e4" + "Hash": "f6b5b788ea3cdec44401645c5896ad8c" }, "gtable": { "Package": "gtable",