Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR R

pdlyr mutate string extract

# You could use stringr::str_extract:

library(stringr)

 df %>%
   dplyr::mutate(new_id = str_extract(id, "[^_]+$"))


#>              id x new_id
#> 1  abcd_123_ABC 1    ABC
#> 2 abc_5234_NHYK 2   NHYK
# The regex says, match one or more (+) of the characters that aren't _ (the negating [^ ]), followed by end of string ($).
Source by stackoverflow.com #
 
PREVIOUS NEXT
Tagged: #pdlyr #mutate #string #extract
ADD COMMENT
Topic
Name
2+4 =