Difference between revisions of "Simple functions"
From kogic.kr
(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=...") |
|||
(3 intermediate revisions by the same user not shown) | |||
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 an element</span></h1> |
− | < | + | <h3 style="color:#aaa; font-style:italic"><span style="font-family:courier new,courier,monospace">Input</span></h3> |
− | < | + | <div style="background:#eee;border:1px solid #ccc;padding:5px 10px;"><span style="font-size:11px"><span style="font-family:courier new,courier,monospace">x <- "AAA@BBB"</span></span></div> |
− | <div style="background:#eee;border:1px solid #ccc;padding:5px 10px;"><span style="font-family:courier new,courier,monospace">split_pick <- function(x , Div_str, Pick_num){<br /> | + | <h3 style="color:#aaa; font-style:italic"><span style="font-family:courier new,courier,monospace">Code</span></h3> |
+ | |||
+ | <div style="background:#eee;border:1px solid #ccc;padding:5px 10px;"><span style="font-size:11px"><span style="font-family:courier new,courier,monospace">split_pick <- function(x , Div_str, Pick_num){<br /> | ||
return(as.character(as.data.table(strsplit(x, Div_str))[Pick_num])) <br /> | return(as.character(as.data.table(strsplit(x, Div_str))[Pick_num])) <br /> | ||
− | }</span></div> | + | }</span></span></div> |
− | <div style="background:#eee;border:1px solid #ccc;padding:5px 10px;"><span style="font-family:courier new,courier,monospace">split_pick(x, "@", 2)</span></div> | + | <div style="background:#eee;border:1px solid #ccc;padding:5px 10px;"><span style="font-size:11px"><span style="font-family:courier new,courier,monospace">split_pick(x, "@", 2)</span></span></div> |
− | <h3 style="color:#aaa;font-style:italic | + | <h3 style="color:#aaa; font-style:italic"><span style="font-family:courier new,courier,monospace">Output</span></h3> |
− | <div style="background:#eee;border:1px solid #ccc;padding:5px 10px;"><span style="font-family:courier new,courier,monospace">"BBB"</span></div> | + | <div style="background:#eee;border:1px solid #ccc;padding:5px 10px;"><span style="font-size:11px"><span style="font-family:courier new,courier,monospace">"BBB"</span></span></div> |
<p> </p> | <p> </p> |
Latest revision as of 13:34, 27 November 2018
Contents
Split the elements of a character vector and select an 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"