能否从行尾开始将一栏分成几栏?

Can one separate column into several columns starting from the end of the line?

我想知道是否有一些秘密参数允许从行尾应用 separate?一些magic_argument

所需的输出如下:

library(dplyr)
df <- data.frame(x = c(NA, "a.b.b", "a.b.d", "b.c"))
df %>% separate(x, c("A", "B"), magic_argument = TRUE)
#>      A    B
#> 1 <NA> <NA>
#> 2    a.b    b
#> 3    a.b    d
#> 4    b    c

尝试:

df %>% separate(x, c("A", "B"), sep="\.(?=[^\.]+$)")
#     A    B
#1 <NA> <NA>
#2  a.b    b
#3  a.b    d
#4    b    c