Keep leading zeros in flextable

Viewed 109

I've created a dataframe with strings. If I pass it on to flextable, the leading zeroes of my strings disappear. I want them there, because then it is possible to left align them, which gives a nicer table.

R <- structure(c(-0.3, -0.1, 0.1, -0.2, 0, 0.2), .Dim = 3:2)
`mystars <- structure(c("*  ", "*  ", "   ", "*  ", "***", "** "), .Dim = 3:2)

r0 <- R < 0  ## store numbers less than zero
R <- formatC(R, format="f", digits=1)  ## format numbers to character
R[!r0] <- sprintf(" %s", R[!r0])  ## insert leading space for non-negative

R1 <- as.data.frame(array(mapply(paste0, R, mystars), dim=dim(R)))

tab <- flextable(R1)
align_text_col(tab, align = "left")
0 Answers
Related