In R, is it possible to extract group capture from a regular expression match? As far as I can tell, none of grep
, grepl
, regexpr
, gregexpr
, sub
, or gsub
return the group captures.
In the data frame below, I want to create a new column or a new data frame such that A1 and B1 are subgroups. for example, A1 would have REF, FOW and NIGHT as it's element and B2 would have NURT, PEGGY and PILLAR. Is there a package that can do that?
NAME <- c("HUGHES", "BAKER", "STONEBOY", "FINN", "BANNY", "GRANT")
ACCOUNT_NO <- c( 003, 004, 005, 006, 007, 008)
kv33 <- c( "A1", "B2", "B2", "A1", "A1", "B2")
KV11 <- c("REF", "NURT", "PEGGY"," FOW","NIGHT", "PILLAR")
(Companies_data <- data.frame(NAME,ACCOUNT_NO,kv33,KV11))
#> NAME ACCOUNT_NO kv33 KV11
#> 1 HUGHES 3 A1 REF
#> 2 BAKER 4 B2 NURT
#> 3 STONEBOY 5 B2 PEGGY
#> 4 FINN 6 A1 FOW
#> 5 BANNY 7 A1 NIGHT
#> 6 GRANT 8 B2 PILLAR