Quantcast
Viewing all articles
Browse latest Browse all 109

Change cells' values in RMarkdown PDF and linebreak

I have the following dataset:

structure(list(...1 = c("Catalunya", "PIB", "Demanda interna1", "Demanda externa1", "Espanya", "PIB", "Demanda interna1", "Demanda externa1", "Zona euro", "PIB", "Demanda interna1", "Demanda externa1", "PIB d'Alemanya", "PIB de França", "PIB d'Itàlia", "Internacional", "PIB de la UE-27", "PIB dels EUA", "PIB del Japó"), `2020` = c(NA, -11.9, -7.4, -4.5, NA, -11.2, -9, -2.2, NA, -6.1, -5.57, -0.53, -3.8, -7.5, -9, NA, -5.6, -2.2, -4.3), `2021` = c(NA, 6.2, 3.8, 2.4, NA, 6.4, 5.9, 0.5, NA, 5.6, 4.24, 1.36, 3.2, 6.4, 8.3, NA, 5.7, 5.8, 2.1), `2022` = c(NA, 5.5, 2.7, 2.8, NA, 5.5, 5.12183164381576, 0.378168356184236, NA, 3.6, 3.76, -0.16, 1.8, 2.5, 3.7, NA, 3.5, 1.9, 1.1), `1r 2023` = c(NA, 3.2, 1.1, 2.1, NA, 4.1, 1.3, 2.8, NA, 1.2, 0.63, 0.57, -0.2, 1, 2.1, NA, 1.1, 1.71772942152937, 2), `2n 2023` = c(NA, 2.1, 1.2, 0.9, NA, 2, 2.2, -0.2, NA, 0.5, 0.46, 0.04, 0.1, 1.1, 0.3, NA, 0.4, 2.38237207285343, 1.7), `3r 2023` = c(NA, 2.1, NA, NA, NA, 1.8, 1.6, 0.2, NA, 0.1, NA, NA, -0.4, 0.7, 0, NA, 0.1, 3, 1.2)), row.names = c(NA, -19L), class = c("tbl_df", "tbl", "data.frame"))

And I am creating a table in Markdown (to PDF), using this code:

options(knitr.kable.NA = "-")p3_1[3,1] <- p3_1[7,1] <- p3_1[11,1] <- "$\\text{Demanda interna}^1$"p3_1[4,1] <- p3_1[8,1] <- p3_1[12,1] <- "$\\text{Demanda externa}^1$"kable(p3_1,      align = "lrrrrrr",      col.names = c("", names(p3_1[-1])),      booktabs=TRUE,      digits=1,      format.args = list(big.mark="."),      linesep = "" ,      caption="Producte interior brut (\\% de variació interanual, llevat dels casos indicats)", escape = FALSE) %>%  add_header_above(c("", "Any" = 3, "Trimestre" = 3), bold=T) %>%   kable_styling(latex_options=c("HOLD_position","scale_down"), bootstrap_options = c("condensed"), position="center") %>%   column_spec(1, bold=T, width="4cm") %>%  column_spec(2:7, width="2cm") %>%  row_spec(0, bold = T) %>%  row_spec(c(1, 5, 9, 16), background="lightgray") %>%  row_spec(19, extra_css = "border-bottom: 1px solid;") %>%  footnote(general="Idescat; Eurostat; INE; BEA; ESRI; Agència Estatal d'Administració Tributària.", general_title = "Font:", footnote_as_chunk = T,)  %>%  footnote(general="$^{A}$Dada avançada. $^{1}$Contribució al creixement. $^{2}$Sèrie original corregida d'efectes de calendari.            $^{3}$En valors constants. Exclou estacions de servei.",  escape = F, general_title = "Nota:", threeparttable = TRUE, footnote_as_chunk = T,) 

Which results in:

Image may be NSFW.
Clik here to view.
enter image description here

How can I delete the "-" in Catalunya, Espanya and Zona Eurorows? So "-" will only appear in those cells where the value is missing.

And also, how can I add a line break in the caption: "Producte interior brut \linebreakhere (% de variació interanual, llevat dels casos indicats)"


Viewing all articles
Browse latest Browse all 109

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>