extract | R Documentation |
extract()
has been superseded in favour of separate_wider_regex()
because it has a more polished API and better handling of problems.
Superseded functions will not go away, but will only receive critical bug
fixes.
Given a regular expression with capturing groups, extract()
turns
each group into a new column. If the groups don't match, or the input
is NA, the output will be NA.
extract( data, col, into, regex = "([[:alnum:]]+)", remove = TRUE, convert = FALSE, ... )
data |
A data frame. |
col |
< |
into |
Names of new variables to create as character vector.
Use |
regex |
A string representing a regular expression used to extract the
desired values. There should be one group (defined by |
remove |
If |
convert |
If NB: this will cause string |
... |
Additional arguments passed on to methods. |
separate()
to split up by a separator.
df <- tibble(x = c(NA, "a-b", "a-d", "b-c", "d-e")) df %>% extract(x, "A") df %>% extract(x, c("A", "B"), "([[:alnum:]]+)-([[:alnum:]]+)") # Now recommended df %>% separate_wider_regex( x, patterns = c(A = "[[:alnum:]]+", "-", B = "[[:alnum:]]+") ) # If no match, NA: df %>% extract(x, c("A", "B"), "([a-d]+)-([a-d]+)")
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.