Simple functions

From kogic.kr
Revision as of 13:26, 27 November 2018 by S (talk | contribs) (Created page with "<h1><span style="font-family:courier new,courier,monospace">Split the elements of a character vector like perl</span></h1> <h3 style="color:#aaa;font-style:italic;"><span style=...")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

Split the elements of a character vector like perl

Input

x <- "AAA@BBB"

Code

split_pick <- function(x , Div_str, Pick_num){

    return(as.character(as.data.table(strsplit(x, Div_str))[Pick_num])) 

}
split_pick(x, "@", 2)

Output

"BBB"