{"id":291,"date":"2013-11-03T17:24:39","date_gmt":"2013-11-03T22:24:39","guid":{"rendered":"http:\/\/homepages.uc.edu\/~yaozo\/wordpress\/?p=291"},"modified":"2013-11-03T17:24:39","modified_gmt":"2013-11-03T22:24:39","slug":"r-substr-substring","status":"publish","type":"post","link":"https:\/\/zhuoyao.net\/index.php\/2013\/11\/03\/r-substr-substring\/","title":{"rendered":"R-substr, substring"},"content":{"rendered":"<p>Retrieve or replace a substring of a character string via the\u00a0substr\u00a0and\u00a0substringfunctions. Additionally, these functions can be used to overwrite a part of a character string.<\/p>\n<div>substr(x, start, stop)<\/div>\n<ul>\n<li>x\u00a0\u2013 A character string.<\/li>\n<li>start\u00a0\u2013 If the characters of\u00a0x\u00a0were numbered, then the number of the first character to be returned (or overwritten).<\/li>\n<li>stop\u00a0\u2013 The number of the last character to be returned (or overwritten).<\/li>\n<\/ul>\n<div>substring(x, first, last=1000000)<\/div>\n<ul>\n<li>x\u00a0\u2013 A character string.<\/li>\n<li>first\u00a0\u2013 If the characters of\u00a0x\u00a0were numbered, then the number of the first character to be returned (or overwritten).<\/li>\n<li>last\u00a0\u2013 The number of the last character to be returned (or overwritten), which is defaulted to 1 million.<\/li>\n<\/ul>\n<p>&nbsp;<\/p>\n<div>Example.\u00a0Below are several simple examples of using\u00a0substr. Notice in the last example of\u00a0substr, where I try to extend the string out past its original length, does not work in this way. The string length cannot be changed using\u00a0substr. Notice that thesubstring\u00a0function has a default setting for the third argument.<\/div>\n<div><a href=\"http:\/\/rfunction.com\/code\/1202\/120220.R\">Download the Code<\/a><\/div>\n<pre>&gt; x &lt;- \"1234567890\"\n&gt; substr(x, 3, 3)\n[1] \"3\"\n&gt; \n&gt; substr(x, 5, 7)\n[1] \"567\"\n&gt; \n&gt; substr(x, 4, 4) &lt;- \"A\"\n&gt; x\n[1] \"123A567890\"\n&gt; \n&gt; substr(x, 2, 4) &lt;- \"TTF\"\n&gt; x\n[1] \"1TTF567890\"\n&gt; \n&gt; substr(x, 9, 12) &lt;- \"ABCD\"\n&gt; x\n[1] \"1TTF5678AB\"\n&gt; \n&gt; substring(x, 5)\n[1] \"5678AB\"\n&gt; \n&gt; substring(x, 5) &lt;- \"...\"\n&gt; x\n[1] \"1TTF...8AB\"<\/pre>\n<div>The\u00a0substring\u00a0function is a little more robust than\u00a0substr.<\/div>\n","protected":false},"excerpt":{"rendered":"<p>Retrieve or replace a substring of a character string via the\u00a0substr\u00a0and\u00a0substringfunctions. Additionally, these functions can be used to overwrite a part of a character string.&hellip; <\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[20],"tags":[],"class_list":["post-291","post","type-post","status-publish","format-standard","hentry","category-r"],"_links":{"self":[{"href":"https:\/\/zhuoyao.net\/index.php\/wp-json\/wp\/v2\/posts\/291","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/zhuoyao.net\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/zhuoyao.net\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/zhuoyao.net\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/zhuoyao.net\/index.php\/wp-json\/wp\/v2\/comments?post=291"}],"version-history":[{"count":0,"href":"https:\/\/zhuoyao.net\/index.php\/wp-json\/wp\/v2\/posts\/291\/revisions"}],"wp:attachment":[{"href":"https:\/\/zhuoyao.net\/index.php\/wp-json\/wp\/v2\/media?parent=291"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/zhuoyao.net\/index.php\/wp-json\/wp\/v2\/categories?post=291"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/zhuoyao.net\/index.php\/wp-json\/wp\/v2\/tags?post=291"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}