Search
 
SCRIPT & CODE EXAMPLE
 

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 ($).
Comment

PREVIOUS NEXT
Code Example
R :: ggplot - subset top 10 in a stack bar plot 
R :: add column value based on row index r 
R :: generate random values binomial law in r 
R :: r select column names starting with 
R :: next element in a loop if error in r 
R :: r studio 
R :: Pass argument to group_by (2) 
R :: r count dataframe 
Rust :: rust lang sleep 
Rust :: rust string to char array 
Rust :: create file rust 
Rust :: remove file rust 
Rust :: add element to vec rust 
Rust :: rust option get value 
Rust :: rust const string 
Rust :: armanriazi•rust•error 
Rust :: rust regex split 
Rust :: armanriazi•rust•static•vs•cons 
Rust :: Find the next smaller positive integer containing the same digits 
Rust :: armanriazi•rust•rc•vs•arc 
Rust :: Counting bits Kernighan style 
Rust :: rust currying, preset some arguments 
Rust :: rust•armanriazi•capacity•reserve 
Lua :: roblox studio teleport on touch 
Lua :: roblox send message script 
Lua :: roblox loop all players 
Lua :: lua metatable assignment 
Lua :: how to get the length of a table in lua 
Lua :: get last characters of string lua 
Lua :: how to make everyone on team see each other name roblox 
ADD CONTENT
Topic
Content
Source link
Name
9+7 =