Skip to content

Instantly share code, notes, and snippets.

@kylebutts
Created November 16, 2020 22:15
Show Gist options
  • Save kylebutts/0f411737220c30ca64a3eddbec2ead6f to your computer and use it in GitHub Desktop.
Save kylebutts/0f411737220c30ca64a3eddbec2ead6f to your computer and use it in GitHub Desktop.
summary_table_body.R
library(tidyverse)
df <- mtcars %>%
group_by(cyl) %>%
summarize(mean_mpg = mean(mpg), sd_mpg = sd(mpg)) %>%
mutate(
mpg_tex = paste0(format(round(mean_mpg, 2), nsmall = 2), " (", format(round(sd_mpg, 2), nsmall = 2), ")"),
tex = paste(cyl, mpg_tex, sep = " & ")
)
cat(df$tex, sep = " \\\\ \n")
#> 4 & 26.66 (4.51) \\
#> 6 & 19.74 (1.45) \\
#> 8 & 15.10 (2.56)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment