如何在R中每两个characters/symbols前面加一个space

How to add a space in front of every two characters/symbols in R

我的矢量图

a <- c( '4152.0', '34152', '235518.3', '1235518.335554', '15235518.3876')

如何在每两个符号前加一个space,但只在一个点前?

'41 52.0', '3 41 52', '23 55 18.3', '1 23 55 18.335554', '15 23 55 18.3876'

prettyNum 有参数 big.intervalbig.mark 支持这个。

prettyNum(a, big.interval = 2, big.mark = " ")
# [1] "          41 52.0" "          3 41 52" "       23 55 18.3"
# [4] "1 23 55 18.335554" " 15 23 55 18.3876"

如果您需要删除前导空格 space,请使用 trimws