Difference between revisions of "Simple functions"

From kogic.kr
Line 1: Line 1:
 +
<p>[[YalPak_Rtip]]</p>
 +
 
<h1><span style="font-family:courier new,courier,monospace">Split the elements of a character vector and select a element</span></h1>
 
<h1><span style="font-family:courier new,courier,monospace">Split the elements of a character vector and select a element</span></h1>
  

Revision as of 13:29, 27 November 2018

YalPak_Rtip

Split the elements of a character vector and select a element

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"