{"id":187671,"date":"2023-03-30T11:11:38","date_gmt":"2023-03-30T15:11:38","guid":{"rendered":"https:\/\/ibkrcampus.com\/?p=187671"},"modified":"2023-03-30T16:36:14","modified_gmt":"2023-03-30T20:36:14","slug":"four-ways-to-reverse-a-string-in-r","status":"publish","type":"post","link":"https:\/\/www.interactivebrokers.com\/campus\/ibkr-quant-news\/four-ways-to-reverse-a-string-in-r\/","title":{"rendered":"Four Ways to Reverse a String in R"},"content":{"rendered":"\n<p><a href=\"https:\/\/theautomatic.net\/category\/r\/\">R<\/a>&nbsp;offers several ways to reverse a string, include some base R options. We go through a few of those in this post. We\u2019ll also compare the computational time for each method.<\/p>\n\n\n\n<p>Reversing a string can be especially useful in bioinformatics (e.g. finding the&nbsp;<a href=\"https:\/\/www.bx.psu.edu\/old\/courses\/bx-fall08\/definitions.html\">reverse compliment<\/a>&nbsp;of a DNA strand). To get started, let\u2019s generate a random string of 10 million DNA bases (we can do this with the&nbsp;<strong>stringi<\/strong>&nbsp;package as well, but for our purposes here, let\u2019s just use base R functions).<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">set.seed(1)\ndna &lt;- paste(sample(c(\"A\", \"T\", \"C\", \"G\"), 10000000, replace = T), collapse = \"\")<\/pre>\n\n\n\n<p><strong>1) Base R with strsplit and paste<\/strong><\/p>\n\n\n\n<p>One way to reverse a string is to use&nbsp;<strong>strsplit<\/strong>&nbsp;with&nbsp;<strong>paste<\/strong>. This is the slowest method that will be shown, but it does get the job done without needing any packages. In this example, we use&nbsp;<strong>strsplit<\/strong>&nbsp;to break the string into a vector of its individual characters. We then reverse this vector using&nbsp;<strong>rev<\/strong>. Finally, we concatenate the vector of characters into a string using&nbsp;<strong>paste<\/strong>.<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">start &lt;- proc.time()\nsplits &lt;- strsplit(dna, \"\")[[1]]\nreversed &lt;- rev(splits)\nfinal_result &lt;- paste(reversed, collapse = \"\")\nend &lt;- proc.time()\n \nprint(end - start)<\/pre>\n\n\n\n<figure class=\"wp-block-image img-twothird\"><img decoding=\"async\" width=\"479\" height=\"206\" data-src=\"\/campus\/wp-content\/uploads\/sites\/2\/2023\/03\/strsplit-and-paste-TheAutomatic.net_.jpg\" alt=\"\" class=\"wp-image-187673 lazyload\" data-srcset=\"https:\/\/ibkrcampus.com\/campus\/wp-content\/uploads\/sites\/2\/2023\/03\/strsplit-and-paste-TheAutomatic.net_.jpg 479w, https:\/\/ibkrcampus.com\/campus\/wp-content\/uploads\/sites\/2\/2023\/03\/strsplit-and-paste-TheAutomatic.net_-300x129.jpg 300w\" data-sizes=\"(max-width: 479px) 100vw, 479px\" src=\"data:image\/svg+xml;base64,PHN2ZyB3aWR0aD0iMSIgaGVpZ2h0PSIxIiB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciPjwvc3ZnPg==\" style=\"--smush-placeholder-width: 479px; aspect-ratio: 479\/206;\" \/><\/figure>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"h-2-base-r-using-utf8-magic\"><strong>2) Base R: Using utf8 magic<\/strong><\/h2>\n\n\n\n<p>This example also does not require any external packages. In this method, we can use the built-in R function&nbsp;<strong>utf8ToInt<\/strong>&nbsp;to convert our DNA string to a vector of integers. We then reverse this vector with the&nbsp;<strong>rev<\/strong>&nbsp;function. Lastly, we convert this reversed vector of integers back to its original encoding \u2013 except now the string is in reverse.<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">start &lt;- proc.time()\nfinal_result &lt;- intToUtf8(rev(utf8ToInt(dna)))\nend &lt;- proc.time()\n \nprint(end - start)<\/pre>\n\n\n\n<figure class=\"wp-block-image img-twothird\"><img decoding=\"async\" width=\"487\" height=\"154\" data-src=\"\/campus\/wp-content\/uploads\/sites\/2\/2023\/03\/reverse-string-integer-theautomatic.net_.jpg\" alt=\"\" class=\"wp-image-187677 lazyload\" data-srcset=\"https:\/\/ibkrcampus.com\/campus\/wp-content\/uploads\/sites\/2\/2023\/03\/reverse-string-integer-theautomatic.net_.jpg 487w, https:\/\/ibkrcampus.com\/campus\/wp-content\/uploads\/sites\/2\/2023\/03\/reverse-string-integer-theautomatic.net_-300x95.jpg 300w\" data-sizes=\"(max-width: 487px) 100vw, 487px\" src=\"data:image\/svg+xml;base64,PHN2ZyB3aWR0aD0iMSIgaGVpZ2h0PSIxIiB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciPjwvc3ZnPg==\" style=\"--smush-placeholder-width: 487px; aspect-ratio: 487\/154;\" \/><\/figure>\n\n\n\n<h2 class=\"wp-block-heading\"><strong>3) The stringi package<\/strong><\/h2>\n\n\n\n<p>Of all the examples presented, this option is the fastest when tested. Here we use the&nbsp;<strong>stri_reverse<\/strong>&nbsp;function from the&nbsp;<a href=\"https:\/\/www.rdocumentation.org\/packages\/stringi\/versions\/1.4.3\">stringi package<\/a>.<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">library(stringi)\n \nstart &lt;- proc.time()\nfinal_result &lt;- stri_reverse(dna)\nend &lt;- proc.time()\n \nprint(end - start)<\/pre>\n\n\n\n<figure class=\"wp-block-image img-twothird\"><img decoding=\"async\" width=\"368\" height=\"158\" data-src=\"\/campus\/wp-content\/uploads\/sites\/2\/2023\/03\/stri_reverse-theautomati-net.jpg\" alt=\"\" class=\"wp-image-187680 lazyload\" data-srcset=\"https:\/\/ibkrcampus.com\/campus\/wp-content\/uploads\/sites\/2\/2023\/03\/stri_reverse-theautomati-net.jpg 368w, https:\/\/ibkrcampus.com\/campus\/wp-content\/uploads\/sites\/2\/2023\/03\/stri_reverse-theautomati-net-300x129.jpg 300w\" data-sizes=\"(max-width: 368px) 100vw, 368px\" src=\"data:image\/svg+xml;base64,PHN2ZyB3aWR0aD0iMSIgaGVpZ2h0PSIxIiB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciPjwvc3ZnPg==\" style=\"--smush-placeholder-width: 368px; aspect-ratio: 368\/158;\" \/><\/figure>\n\n\n\n<h2 class=\"wp-block-heading\"><strong>4) The Biostrings package<\/strong><\/h2>\n\n\n\n<p>Our last example uses the&nbsp;<a href=\"https:\/\/web.stanford.edu\/class\/bios221\/labs\/biostrings\/lab_1_biostrings.html\">Biostrings package<\/a>, which contains a collection of functions useful for working with DNA-string data. One function, called&nbsp;<strong>str_rev<\/strong>, can reverse strings. You can download and load the Biostrings package like this:<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">source(\"https:\/\/bioconductor.org\/biocLite.R\")\nbiocLite(\"Biostrings\")\n \nlibrary(Biostrings)<\/pre>\n\n\n\n<p>Then, all we have to do is input our DNA string into the&nbsp;<strong>str_rev<\/strong>&nbsp;function and we get our result.<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">start &lt;- proc.time()\nfinal_result &lt;- str_rev(dna)\nend &lt;- proc.time()\n \nprint(end - start)<\/pre>\n\n\n\n<figure class=\"wp-block-image img-twothird\"><img decoding=\"async\" width=\"295\" height=\"167\" data-src=\"\/campus\/wp-content\/uploads\/sites\/2\/2023\/03\/biostrings-reverse-a-string-in-r.jpg\" alt=\"\" class=\"wp-image-187681 lazyload\" src=\"data:image\/svg+xml;base64,PHN2ZyB3aWR0aD0iMSIgaGVpZ2h0PSIxIiB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciPjwvc3ZnPg==\" style=\"--smush-placeholder-width: 295px; aspect-ratio: 295\/167;\"><\/figure>\n\n\n\n<p><em>Originally posted on <a href=\"https:\/\/theautomatic.net\/2019\/05\/17\/four-ways-to-reverse-a-string-in-r\/\">TheAutomatic.net<\/a> blog.<\/em><\/p>\n","protected":false},"excerpt":{"rendered":"<p>R offers several ways to reverse a string, include some base R options. We go through a few of those in this post. <\/p>\n","protected":false},"author":388,"featured_media":168995,"comment_status":"closed","ping_status":"closed","sticky":true,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[339,343,338,341,342],"tags":[15035,806,487,15033,6591,15034],"contributors-categories":[13695],"class_list":{"0":"post-187671","1":"post","2":"type-post","3":"status-publish","4":"format-standard","5":"has-post-thumbnail","7":"category-data-science","8":"category-programing-languages","9":"category-ibkr-quant-news","10":"category-quant-development","11":"category-r-development","12":"tag-biostrings-package","13":"tag-data-science","14":"tag-r","15":"tag-reverse-a-string","16":"tag-rstats","17":"tag-stringi-package","18":"contributors-categories-theautomatic-net"},"pp_statuses_selecting_workflow":false,"pp_workflow_action":"current","pp_status_selection":"publish","acf":[],"yoast_head":"<!-- This site is optimized with the Yoast SEO Premium plugin v26.9 (Yoast SEO v27.4) - https:\/\/yoast.com\/product\/yoast-seo-premium-wordpress\/ -->\n<title>Four Ways to Reverse a String in R | IBKR Quant<\/title>\n<meta name=\"description\" content=\"R offers several ways to reverse a string, include some base R options. We go through a few of those in this post.\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.interactivebrokers.com\/campus\/wp-json\/wp\/v2\/posts\/187671\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Four Ways to Reverse a String in R | IBKR Campus US\" \/>\n<meta property=\"og:description\" content=\"R offers several ways to reverse a string, include some base R options. We go through a few of those in this post.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.interactivebrokers.com\/campus\/ibkr-quant-news\/four-ways-to-reverse-a-string-in-r\/\" \/>\n<meta property=\"og:site_name\" content=\"IBKR Campus US\" \/>\n<meta property=\"article:published_time\" content=\"2023-03-30T15:11:38+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2023-03-30T20:36:14+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/www.interactivebrokers.com\/campus\/wp-content\/uploads\/sites\/2\/2022\/11\/big-data-prevent-1.jpg\" \/>\n\t<meta property=\"og:image:width\" content=\"1000\" \/>\n\t<meta property=\"og:image:height\" content=\"563\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/jpeg\" \/>\n<meta name=\"author\" content=\"Andrew Treadway\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Andrew Treadway\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"3 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\n\t    \"@context\": \"https:\\\/\\\/schema.org\",\n\t    \"@graph\": [\n\t        {\n\t            \"@type\": \"NewsArticle\",\n\t            \"@id\": \"https:\\\/\\\/www.interactivebrokers.com\\\/campus\\\/ibkr-quant-news\\\/four-ways-to-reverse-a-string-in-r\\\/#article\",\n\t            \"isPartOf\": {\n\t                \"@id\": \"https:\\\/\\\/www.interactivebrokers.com\\\/campus\\\/ibkr-quant-news\\\/four-ways-to-reverse-a-string-in-r\\\/\"\n\t            },\n\t            \"author\": {\n\t                \"name\": \"Andrew Treadway\",\n\t                \"@id\": \"https:\\\/\\\/ibkrcampus.com\\\/campus\\\/#\\\/schema\\\/person\\\/d4018570a16fb867f1c08412fc9c64bc\"\n\t            },\n\t            \"headline\": \"Four Ways to Reverse a String in R\",\n\t            \"datePublished\": \"2023-03-30T15:11:38+00:00\",\n\t            \"dateModified\": \"2023-03-30T20:36:14+00:00\",\n\t            \"mainEntityOfPage\": {\n\t                \"@id\": \"https:\\\/\\\/www.interactivebrokers.com\\\/campus\\\/ibkr-quant-news\\\/four-ways-to-reverse-a-string-in-r\\\/\"\n\t            },\n\t            \"wordCount\": 350,\n\t            \"publisher\": {\n\t                \"@id\": \"https:\\\/\\\/ibkrcampus.com\\\/campus\\\/#organization\"\n\t            },\n\t            \"image\": {\n\t                \"@id\": \"https:\\\/\\\/www.interactivebrokers.com\\\/campus\\\/ibkr-quant-news\\\/four-ways-to-reverse-a-string-in-r\\\/#primaryimage\"\n\t            },\n\t            \"thumbnailUrl\": \"https:\\\/\\\/www.interactivebrokers.com\\\/campus\\\/wp-content\\\/uploads\\\/sites\\\/2\\\/2022\\\/11\\\/big-data-prevent-1.jpg\",\n\t            \"keywords\": [\n\t                \"Biostrings package\",\n\t                \"Data Science\",\n\t                \"R\",\n\t                \"Reverse a String\",\n\t                \"rstats\",\n\t                \"stringi package\"\n\t            ],\n\t            \"articleSection\": [\n\t                \"Data Science\",\n\t                \"Programming Languages\",\n\t                \"Quant\",\n\t                \"Quant Development\",\n\t                \"R Development\"\n\t            ],\n\t            \"inLanguage\": \"en-US\"\n\t        },\n\t        {\n\t            \"@type\": \"WebPage\",\n\t            \"@id\": \"https:\\\/\\\/www.interactivebrokers.com\\\/campus\\\/ibkr-quant-news\\\/four-ways-to-reverse-a-string-in-r\\\/\",\n\t            \"url\": \"https:\\\/\\\/www.interactivebrokers.com\\\/campus\\\/ibkr-quant-news\\\/four-ways-to-reverse-a-string-in-r\\\/\",\n\t            \"name\": \"Four Ways to Reverse a String in R | IBKR Campus US\",\n\t            \"isPartOf\": {\n\t                \"@id\": \"https:\\\/\\\/ibkrcampus.com\\\/campus\\\/#website\"\n\t            },\n\t            \"primaryImageOfPage\": {\n\t                \"@id\": \"https:\\\/\\\/www.interactivebrokers.com\\\/campus\\\/ibkr-quant-news\\\/four-ways-to-reverse-a-string-in-r\\\/#primaryimage\"\n\t            },\n\t            \"image\": {\n\t                \"@id\": \"https:\\\/\\\/www.interactivebrokers.com\\\/campus\\\/ibkr-quant-news\\\/four-ways-to-reverse-a-string-in-r\\\/#primaryimage\"\n\t            },\n\t            \"thumbnailUrl\": \"https:\\\/\\\/www.interactivebrokers.com\\\/campus\\\/wp-content\\\/uploads\\\/sites\\\/2\\\/2022\\\/11\\\/big-data-prevent-1.jpg\",\n\t            \"datePublished\": \"2023-03-30T15:11:38+00:00\",\n\t            \"dateModified\": \"2023-03-30T20:36:14+00:00\",\n\t            \"description\": \"R offers several ways to reverse a string, include some base R options. We go through a few of those in this post.\",\n\t            \"inLanguage\": \"en-US\",\n\t            \"potentialAction\": [\n\t                {\n\t                    \"@type\": \"ReadAction\",\n\t                    \"target\": [\n\t                        \"https:\\\/\\\/www.interactivebrokers.com\\\/campus\\\/ibkr-quant-news\\\/four-ways-to-reverse-a-string-in-r\\\/\"\n\t                    ]\n\t                }\n\t            ]\n\t        },\n\t        {\n\t            \"@type\": \"ImageObject\",\n\t            \"inLanguage\": \"en-US\",\n\t            \"@id\": \"https:\\\/\\\/www.interactivebrokers.com\\\/campus\\\/ibkr-quant-news\\\/four-ways-to-reverse-a-string-in-r\\\/#primaryimage\",\n\t            \"url\": \"https:\\\/\\\/www.interactivebrokers.com\\\/campus\\\/wp-content\\\/uploads\\\/sites\\\/2\\\/2022\\\/11\\\/big-data-prevent-1.jpg\",\n\t            \"contentUrl\": \"https:\\\/\\\/www.interactivebrokers.com\\\/campus\\\/wp-content\\\/uploads\\\/sites\\\/2\\\/2022\\\/11\\\/big-data-prevent-1.jpg\",\n\t            \"width\": 1000,\n\t            \"height\": 563,\n\t            \"caption\": \"Big Data prevent\"\n\t        },\n\t        {\n\t            \"@type\": \"WebSite\",\n\t            \"@id\": \"https:\\\/\\\/ibkrcampus.com\\\/campus\\\/#website\",\n\t            \"url\": \"https:\\\/\\\/ibkrcampus.com\\\/campus\\\/\",\n\t            \"name\": \"IBKR Campus US\",\n\t            \"description\": \"Financial Education from Interactive Brokers\",\n\t            \"publisher\": {\n\t                \"@id\": \"https:\\\/\\\/ibkrcampus.com\\\/campus\\\/#organization\"\n\t            },\n\t            \"potentialAction\": [\n\t                {\n\t                    \"@type\": \"SearchAction\",\n\t                    \"target\": {\n\t                        \"@type\": \"EntryPoint\",\n\t                        \"urlTemplate\": \"https:\\\/\\\/ibkrcampus.com\\\/campus\\\/?s={search_term_string}\"\n\t                    },\n\t                    \"query-input\": {\n\t                        \"@type\": \"PropertyValueSpecification\",\n\t                        \"valueRequired\": true,\n\t                        \"valueName\": \"search_term_string\"\n\t                    }\n\t                }\n\t            ],\n\t            \"inLanguage\": \"en-US\"\n\t        },\n\t        {\n\t            \"@type\": \"Organization\",\n\t            \"@id\": \"https:\\\/\\\/ibkrcampus.com\\\/campus\\\/#organization\",\n\t            \"name\": \"Interactive Brokers\",\n\t            \"alternateName\": \"IBKR\",\n\t            \"url\": \"https:\\\/\\\/ibkrcampus.com\\\/campus\\\/\",\n\t            \"logo\": {\n\t                \"@type\": \"ImageObject\",\n\t                \"inLanguage\": \"en-US\",\n\t                \"@id\": \"https:\\\/\\\/ibkrcampus.com\\\/campus\\\/#\\\/schema\\\/logo\\\/image\\\/\",\n\t                \"url\": \"https:\\\/\\\/www.interactivebrokers.com\\\/campus\\\/wp-content\\\/uploads\\\/sites\\\/2\\\/2024\\\/05\\\/ibkr-campus-logo.jpg\",\n\t                \"contentUrl\": \"https:\\\/\\\/www.interactivebrokers.com\\\/campus\\\/wp-content\\\/uploads\\\/sites\\\/2\\\/2024\\\/05\\\/ibkr-campus-logo.jpg\",\n\t                \"width\": 669,\n\t                \"height\": 669,\n\t                \"caption\": \"Interactive Brokers\"\n\t            },\n\t            \"image\": {\n\t                \"@id\": \"https:\\\/\\\/ibkrcampus.com\\\/campus\\\/#\\\/schema\\\/logo\\\/image\\\/\"\n\t            },\n\t            \"publishingPrinciples\": \"https:\\\/\\\/www.interactivebrokers.com\\\/campus\\\/about-ibkr-campus\\\/\",\n\t            \"ethicsPolicy\": \"https:\\\/\\\/www.interactivebrokers.com\\\/campus\\\/cyber-security-notice\\\/\"\n\t        },\n\t        {\n\t            \"@type\": \"Person\",\n\t            \"@id\": \"https:\\\/\\\/ibkrcampus.com\\\/campus\\\/#\\\/schema\\\/person\\\/d4018570a16fb867f1c08412fc9c64bc\",\n\t            \"name\": \"Andrew Treadway\",\n\t            \"description\": \"Andrew Treadway currently works as a Senior Data Scientist, and has experience doing analytics, software automation, and ETL. He completed a master\u2019s degree in computer science \\\/ machine learning, and an undergraduate degree in pure mathematics. Connect with him on LinkedIn: https:\\\/\\\/www.linkedin.com\\\/in\\\/andrew-treadway-a3b19b103\\\/In addition to TheAutomatic.net blog, he also teaches in-person courses on Python and R through my NYC meetup: more details.\",\n\t            \"sameAs\": [\n\t                \"https:\\\/\\\/theautomatic.net\\\/about-me\\\/\"\n\t            ],\n\t            \"url\": \"https:\\\/\\\/www.interactivebrokers.com\\\/campus\\\/author\\\/andrewtreadway\\\/\"\n\t        }\n\t    ]\n\t}<\/script>\n<!-- \/ Yoast SEO Premium plugin. -->","yoast_head_json":{"title":"Four Ways to Reverse a String in R | IBKR Quant","description":"R offers several ways to reverse a string, include some base R options. We go through a few of those in this post.","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/www.interactivebrokers.com\/campus\/wp-json\/wp\/v2\/posts\/187671\/","og_locale":"en_US","og_type":"article","og_title":"Four Ways to Reverse a String in R | IBKR Campus US","og_description":"R offers several ways to reverse a string, include some base R options. We go through a few of those in this post.","og_url":"https:\/\/www.interactivebrokers.com\/campus\/ibkr-quant-news\/four-ways-to-reverse-a-string-in-r\/","og_site_name":"IBKR Campus US","article_published_time":"2023-03-30T15:11:38+00:00","article_modified_time":"2023-03-30T20:36:14+00:00","og_image":[{"width":1000,"height":563,"url":"https:\/\/www.interactivebrokers.com\/campus\/wp-content\/uploads\/sites\/2\/2022\/11\/big-data-prevent-1.jpg","type":"image\/jpeg"}],"author":"Andrew Treadway","twitter_card":"summary_large_image","twitter_misc":{"Written by":"Andrew Treadway","Est. reading time":"3 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"NewsArticle","@id":"https:\/\/www.interactivebrokers.com\/campus\/ibkr-quant-news\/four-ways-to-reverse-a-string-in-r\/#article","isPartOf":{"@id":"https:\/\/www.interactivebrokers.com\/campus\/ibkr-quant-news\/four-ways-to-reverse-a-string-in-r\/"},"author":{"name":"Andrew Treadway","@id":"https:\/\/ibkrcampus.com\/campus\/#\/schema\/person\/d4018570a16fb867f1c08412fc9c64bc"},"headline":"Four Ways to Reverse a String in R","datePublished":"2023-03-30T15:11:38+00:00","dateModified":"2023-03-30T20:36:14+00:00","mainEntityOfPage":{"@id":"https:\/\/www.interactivebrokers.com\/campus\/ibkr-quant-news\/four-ways-to-reverse-a-string-in-r\/"},"wordCount":350,"publisher":{"@id":"https:\/\/ibkrcampus.com\/campus\/#organization"},"image":{"@id":"https:\/\/www.interactivebrokers.com\/campus\/ibkr-quant-news\/four-ways-to-reverse-a-string-in-r\/#primaryimage"},"thumbnailUrl":"https:\/\/www.interactivebrokers.com\/campus\/wp-content\/uploads\/sites\/2\/2022\/11\/big-data-prevent-1.jpg","keywords":["Biostrings package","Data Science","R","Reverse a String","rstats","stringi package"],"articleSection":["Data Science","Programming Languages","Quant","Quant Development","R Development"],"inLanguage":"en-US"},{"@type":"WebPage","@id":"https:\/\/www.interactivebrokers.com\/campus\/ibkr-quant-news\/four-ways-to-reverse-a-string-in-r\/","url":"https:\/\/www.interactivebrokers.com\/campus\/ibkr-quant-news\/four-ways-to-reverse-a-string-in-r\/","name":"Four Ways to Reverse a String in R | IBKR Campus US","isPartOf":{"@id":"https:\/\/ibkrcampus.com\/campus\/#website"},"primaryImageOfPage":{"@id":"https:\/\/www.interactivebrokers.com\/campus\/ibkr-quant-news\/four-ways-to-reverse-a-string-in-r\/#primaryimage"},"image":{"@id":"https:\/\/www.interactivebrokers.com\/campus\/ibkr-quant-news\/four-ways-to-reverse-a-string-in-r\/#primaryimage"},"thumbnailUrl":"https:\/\/www.interactivebrokers.com\/campus\/wp-content\/uploads\/sites\/2\/2022\/11\/big-data-prevent-1.jpg","datePublished":"2023-03-30T15:11:38+00:00","dateModified":"2023-03-30T20:36:14+00:00","description":"R offers several ways to reverse a string, include some base R options. We go through a few of those in this post.","inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.interactivebrokers.com\/campus\/ibkr-quant-news\/four-ways-to-reverse-a-string-in-r\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.interactivebrokers.com\/campus\/ibkr-quant-news\/four-ways-to-reverse-a-string-in-r\/#primaryimage","url":"https:\/\/www.interactivebrokers.com\/campus\/wp-content\/uploads\/sites\/2\/2022\/11\/big-data-prevent-1.jpg","contentUrl":"https:\/\/www.interactivebrokers.com\/campus\/wp-content\/uploads\/sites\/2\/2022\/11\/big-data-prevent-1.jpg","width":1000,"height":563,"caption":"Big Data prevent"},{"@type":"WebSite","@id":"https:\/\/ibkrcampus.com\/campus\/#website","url":"https:\/\/ibkrcampus.com\/campus\/","name":"IBKR Campus US","description":"Financial Education from Interactive Brokers","publisher":{"@id":"https:\/\/ibkrcampus.com\/campus\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/ibkrcampus.com\/campus\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/ibkrcampus.com\/campus\/#organization","name":"Interactive Brokers","alternateName":"IBKR","url":"https:\/\/ibkrcampus.com\/campus\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/ibkrcampus.com\/campus\/#\/schema\/logo\/image\/","url":"https:\/\/www.interactivebrokers.com\/campus\/wp-content\/uploads\/sites\/2\/2024\/05\/ibkr-campus-logo.jpg","contentUrl":"https:\/\/www.interactivebrokers.com\/campus\/wp-content\/uploads\/sites\/2\/2024\/05\/ibkr-campus-logo.jpg","width":669,"height":669,"caption":"Interactive Brokers"},"image":{"@id":"https:\/\/ibkrcampus.com\/campus\/#\/schema\/logo\/image\/"},"publishingPrinciples":"https:\/\/www.interactivebrokers.com\/campus\/about-ibkr-campus\/","ethicsPolicy":"https:\/\/www.interactivebrokers.com\/campus\/cyber-security-notice\/"},{"@type":"Person","@id":"https:\/\/ibkrcampus.com\/campus\/#\/schema\/person\/d4018570a16fb867f1c08412fc9c64bc","name":"Andrew Treadway","description":"Andrew Treadway currently works as a Senior Data Scientist, and has experience doing analytics, software automation, and ETL. He completed a master\u2019s degree in computer science \/ machine learning, and an undergraduate degree in pure mathematics. Connect with him on LinkedIn: https:\/\/www.linkedin.com\/in\/andrew-treadway-a3b19b103\/In addition to TheAutomatic.net blog, he also teaches in-person courses on Python and R through my NYC meetup: more details.","sameAs":["https:\/\/theautomatic.net\/about-me\/"],"url":"https:\/\/www.interactivebrokers.com\/campus\/author\/andrewtreadway\/"}]}},"jetpack_featured_media_url":"https:\/\/www.interactivebrokers.com\/campus\/wp-content\/uploads\/sites\/2\/2022\/11\/big-data-prevent-1.jpg","_links":{"self":[{"href":"https:\/\/ibkrcampus.com\/campus\/wp-json\/wp\/v2\/posts\/187671","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/ibkrcampus.com\/campus\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/ibkrcampus.com\/campus\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/ibkrcampus.com\/campus\/wp-json\/wp\/v2\/users\/388"}],"replies":[{"embeddable":true,"href":"https:\/\/ibkrcampus.com\/campus\/wp-json\/wp\/v2\/comments?post=187671"}],"version-history":[{"count":0,"href":"https:\/\/ibkrcampus.com\/campus\/wp-json\/wp\/v2\/posts\/187671\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/ibkrcampus.com\/campus\/wp-json\/wp\/v2\/media\/168995"}],"wp:attachment":[{"href":"https:\/\/ibkrcampus.com\/campus\/wp-json\/wp\/v2\/media?parent=187671"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/ibkrcampus.com\/campus\/wp-json\/wp\/v2\/categories?post=187671"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/ibkrcampus.com\/campus\/wp-json\/wp\/v2\/tags?post=187671"},{"taxonomy":"contributors-categories","embeddable":true,"href":"https:\/\/ibkrcampus.com\/campus\/wp-json\/wp\/v2\/contributors-categories?post=187671"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}