Hi,
I am trying to use extract to handle optional substrings. For example,
library(tidyverse)
df <- as.tibble(c(
"A = X0 -> X1",
"B = Y1" ))
df %>% extract(value, into = c("variable", "v0", "v1"),
regex = "(\\w+) = (\\w+) -> (\\w+)")
#> # A tibble: 2 x 3
#> variable v0 v1
#> <chr> <chr> <chr>
#> 1 A X0 X1
#> 2 <NA> <NA> <NA>
Created on 2018-09-04 by the reprex package (v0.2.0).
I want to be able to match the second row and extract vlaue "B" and "Y1" to "variable" and "v1", and leave v0 empty (NA).
This is probably a general regex question beyond my skill level. Please share your suggestions/solutions.
Thanks,
Dong