how to put brackets around a printed value

Hi all,
Quick question regarding how to automate a process I currently have to do by hand. I have a function that I created to create APA formatted flextable's of Bayesian models and it's almost complete, except for a few more things.

The following line is part of a larger script I wrote to build my tables. It unites the two 95% Highest Density Interval columns (i.e. the upper and lower bounds):

unite("89% HDI", CI_low:CI_high, sep = ", ", remove = TRUE, na.rm = FALSE) %>% 

But I would like to add something in here to automatically add brackets around the output, in true APA style.

Currently, output for each row currently looks like: x, y
And I'd like it to look like: [x, y]

Is there a way to get R to enclose each row's results with brackets so I don't have to do it myself in Word later?

Like this?

Df <- data.frame(LDI=c(1,2,3),UDI=c(2,3,4))
library(dplyr,warn.conflicts = FALSE)
Df %>% unite("Full_HDI",LDI:UDI,sep=",") %>% mutate("Full_HDI"=paste0('[',Full_HDI,']'))
#>   Full_HDI
#> 1    [1,2]
#> 2    [2,3]
#> 3    [3,4]

Created on 2020-12-09 by the reprex package (v0.3.0)

1 Like

This topic was automatically closed 7 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.

Exactly like that!! Thanks!!!