{"id":563,"date":"2022-09-08T08:38:04","date_gmt":"2022-08-29T10:47:59","guid":{"rendered":"https:\/\/www.silicloud.com\/blog\/uncategorized\/how-to-utilize-sub-and-gsub-functions-in-r\/"},"modified":"2024-03-16T15:37:10","modified_gmt":"2024-03-16T15:37:10","slug":"how-to-utilize-sub-and-gsub-functions-in-r","status":"publish","type":"post","link":"https:\/\/www.silicloud.com\/blog\/how-to-utilize-sub-and-gsub-functions-in-r\/","title":{"rendered":"How to utilize sub() and gsub() functions in R"},"content":{"rendered":"<h3>Here is one possible paraphrase of the introduction:<\/h3>\n<p>&#8220;In this section, we will provide an introductory overview.&#8221;<\/p>\n<p>In <a href=\"https:\/\/en.wikipedia.org\/wiki\/R_(programming_language)\">R,<\/a> the sub() and gsub() functions can be used to replace a string or characters in a vector or data frame with a designated string. These functions come in handy for making modifications on extensive sets of data.<\/p>\n<p>In this article, you will discover the utility of using the sub() and gsub() functions in R.<\/p>\n<h2>Requirements<\/h2>\n<p>To finish this tutorial, you will require the following:<\/p>\n<ul class=\"post-ul\">\n<li>R installed locally or on a server.<\/li>\n<\/ul>\n<h2>The format of sub() and gsub() functions<\/h2>\n<p>The fundamental syntax for sub() is:<\/p>\n<pre class=\"post-pre\"><code>sub<span class=\"token punctuation\">(<\/span>pattern<span class=\"token punctuation\">,<\/span> replacement<span class=\"token punctuation\">,<\/span> x<span class=\"token punctuation\">)<\/span>\r\n<\/code><\/pre>\n<p>The fundamental syntax for utilizing gsub() is:<\/p>\n<pre class=\"post-pre\"><code>gsub<span class=\"token punctuation\">(<\/span>pattern<span class=\"token punctuation\">,<\/span> replacement<span class=\"token punctuation\">,<\/span> x<span class=\"token punctuation\">)<\/span>\r\n<\/code><\/pre>\n<p>You need to provide a pattern, a replacement, and a vector or data frame when using the sub() and gsub() functions.<\/p>\n<ul class=\"post-ul\">\n<li>pattern: The pattern or the string which you want to be substituted.<\/li>\n<li>replacement: A input string to substitute the pattern string.<\/li>\n<li>x: A vector or a data frame to substitute the strings.<\/li>\n<\/ul>\n<p>The pattern can be expressed as a regular expression (regex) as well.<\/p>\n<p>Now that you have grasped the syntax, you can proceed to the execution.<\/p>\n<h2>The sub() Function in the R programming language.<\/h2>\n<p>In R, the sub() function is used to substitute the string within a vector or a data frame with either the input or a designated string.<\/p>\n<p>The sub() function&#8217;s drawback is that it only replaces the initial instance.<\/p>\n<h3>Using the sub() function.<\/h3>\n<p>In this instance, discover the method of using the sub() function to swap a string pattern with a different string.<\/p>\n<pre class=\"post-pre\"><code><span class=\"token comment\"># the input vector <\/span>\r\ndf<span class=\"token operator\">&lt;-<\/span><span class=\"token string\">\"R is an open-source programming language widely used for data analysis and statistical computing.\"<\/span>\r\n\r\n<span class=\"token comment\"># the replacement<\/span>\r\nsub<span class=\"token punctuation\">(<\/span><span class=\"token string\">'R'<\/span><span class=\"token punctuation\">,<\/span><span class=\"token string\">'The R language'<\/span><span class=\"token punctuation\">,<\/span>df<span class=\"token punctuation\">)<\/span>\r\n<\/code><\/pre>\n<p>Executing this command produces the subsequent result.<\/p>\n<pre class=\"post-pre\"><code><\/code><\/pre>\n<div class=\"secondary-code-label\" title=\"Output\">Output<\/div>\n<pre class=\"post-pre\"><code><\/code><\/pre>\n<p>&#8220;The R language is an open-source programming language widely used for data analysis and statistical computing.&#8221;<\/p>\n<pre class=\"post-pre\"><code><\/code><\/pre>\n<p>The sub() function substitutes the occurrence of &#8216;R&#8217; in the vector with the string &#8216;The R language&#8217;.<\/p>\n<p>In this instance, only one instance of pattern matching took place. Let&#8217;s ponder what would occur if there were several instances of pattern matches.<\/p>\n<pre class=\"post-pre\"><code><span class=\"token comment\"># the input vector<\/span>\r\ndf<span class=\"token operator\">&lt;-<\/span><span class=\"token string\">\"In this tutorial, we will install R and show how to add packages from the official Comprehensive R Archive Network (CRAN).\"<\/span>\r\n\r\n<span class=\"token comment\"># the replacement<\/span>\r\nsub<span class=\"token punctuation\">(<\/span><span class=\"token string\">'R'<\/span><span class=\"token punctuation\">,<\/span><span class=\"token string\">'The R language'<\/span><span class=\"token punctuation\">,<\/span>df<span class=\"token punctuation\">)<\/span>\r\n<\/code><\/pre>\n<p>Executing this command produces the subsequent results.<\/p>\n<pre class=\"post-pre\"><code>\"In this tutorial, we will install The R language and show how to add packages from the official Comprehensive R Archive Network (CRAN).\"\r\n<\/code><\/pre>\n<p>In this particular case, you can see that the sub() function has substituted the initial instance of the string &#8216;R&#8217; with &#8216;The R language&#8217;. However, the subsequent occurrence within the string remains unaffected.<\/p>\n<h3>Utilizing the sub() function in combination with a data frame.<\/h3>\n<p>The sub() function is also compatible with data frames.<\/p>\n<pre class=\"post-pre\"><code><span class=\"token comment\"># creating a data frame<\/span>\r\ndf<span class=\"token operator\">&lt;-<\/span>data.frame<span class=\"token punctuation\">(<\/span>Creature<span class=\"token operator\">=<\/span>c<span class=\"token punctuation\">(<\/span><span class=\"token string\">'Starfish'<\/span><span class=\"token punctuation\">,<\/span><span class=\"token string\">'Blue Crab'<\/span><span class=\"token punctuation\">,<\/span><span class=\"token string\">'Bluefin Tuna'<\/span><span class=\"token punctuation\">,<\/span><span class=\"token string\">'Blue Shark'<\/span><span class=\"token punctuation\">,<\/span><span class=\"token string\">'Blue Whale'<\/span><span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">,<\/span>Population<span class=\"token operator\">=<\/span>c<span class=\"token punctuation\">(<\/span><span class=\"token number\">5<\/span><span class=\"token punctuation\">,<\/span><span class=\"token number\">6<\/span><span class=\"token punctuation\">,<\/span><span class=\"token number\">4<\/span><span class=\"token punctuation\">,<\/span><span class=\"token number\">2<\/span><span class=\"token punctuation\">,<\/span><span class=\"token number\">2<\/span><span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">)<\/span>\r\n\r\n<span class=\"token comment\"># data frame<\/span>\r\ndf\r\n<\/code><\/pre>\n<p>The data frame that follows will be generated.<\/p>\n<pre class=\"post-pre\"><code>      Creature Population\r\n1     Starfish          5\r\n2    Blue Crab          6\r\n3 Bluefin Tuna          4\r\n4   Blue Shark          2\r\n5   Blue Whale          2\r\n<\/code><\/pre>\n<p>Replace the term &#8216;Blue&#8217; with &#8216;Green&#8217; in the given statement.<\/p>\n<pre class=\"post-pre\"><code><span class=\"token comment\"># substituting the values<\/span>\r\nsub<span class=\"token punctuation\">(<\/span><span class=\"token string\">'Blue'<\/span><span class=\"token punctuation\">,<\/span><span class=\"token string\">'Green'<\/span><span class=\"token punctuation\">,<\/span>df<span class=\"token punctuation\">)<\/span>\r\n<\/code><\/pre>\n<p>Executing this command produces the subsequent result.<\/p>\n<pre class=\"post-pre\"><code><\/code><\/pre>\n<div class=\"secondary-code-label\" title=\"Output\">Output<\/div>\n<pre class=\"post-pre\"><code><\/code><\/pre>\n<p>&#8220;c(\\&#8221;Starfish\\&#8221;, \\&#8221;Green Crab\\&#8221;, \\&#8221;Bluefin Tuna\\&#8221;, \\&#8221;Blue Shark\\&#8221;, \\&#8221;Blue Whale\\&#8221;)&#8221; &#8220;c(5, 6, 4, 2, 2)&#8221;<\/p>\n<pre class=\"post-pre\"><code><\/code><\/pre>\n<p>You have the option to specify a specific column where you want to replace every instance of &#8216;Blue&#8217; with &#8216;Green&#8217;.<\/p>\n<pre class=\"post-pre\"><code><span class=\"token comment\"># substituting the values<\/span>\r\nsub<span class=\"token punctuation\">(<\/span><span class=\"token string\">'Blue'<\/span><span class=\"token punctuation\">,<\/span><span class=\"token string\">'Green'<\/span><span class=\"token punctuation\">,<\/span>df<span class=\"token operator\">$<\/span>Creature<span class=\"token punctuation\">)<\/span>\r\n<\/code><\/pre>\n<p>Executing this command produces the subsequent result.<\/p>\n<pre class=\"post-pre\"><code><\/code><\/pre>\n<div class=\"secondary-code-label\" title=\"Output\">Output<\/div>\n<pre class=\"post-pre\"><code><\/code><\/pre>\n<p>&#8220;Starfish&#8221; &#8220;Green Crab&#8221; &#8220;Greenfin Tuna&#8221; &#8220;Green Shark&#8221; &#8220;Green Whale&#8221;<\/p>\n<pre class=\"post-pre\"><code><\/code><\/pre>\n<p>Every occurrence of the characters &#8216;Blue&#8217; has been substituted with &#8216;Green&#8217;.<\/p>\n<h2>The R function gsub()<\/h2>\n<p>In R, the gsub() function is employed to perform replacement tasks by substituting the specified values with the input.<\/p>\n<p>In contrast to the sub() function, the gsub() function performs a global substitution for all occurrences.<\/p>\n<h3>1. Employing the gsub() function.<\/h3>\n<p>In this instance, discover how to replace a string pattern using the gsub() function.<\/p>\n<pre class=\"post-pre\"><code><span class=\"token comment\"># the input vector<\/span>\r\ndf<span class=\"token operator\">&lt;-<\/span><span class=\"token string\">\"In this tutorial, we will install R and show how to add packages from the official Comprehensive R Archive Network (CRAN).\"<\/span>\r\n<\/code><\/pre>\n<p>This data contains multiple instances where &#8216;R&#8217; is written.<\/p>\n<pre class=\"post-pre\"><code><span class=\"token comment\"># substituting the values using gsub()<\/span>\r\ngsub<span class=\"token punctuation\">(<\/span><span class=\"token string\">'R'<\/span><span class=\"token punctuation\">,<\/span><span class=\"token string\">'The R language'<\/span><span class=\"token punctuation\">,<\/span>df<span class=\"token punctuation\">)<\/span>\r\n<\/code><\/pre>\n<pre class=\"post-pre\"><code><\/code><\/pre>\n<div class=\"secondary-code-label\" title=\"Output\">Output<\/div>\n<pre class=\"post-pre\"><code><\/code><\/pre>\n<p>&#8220;In this tutorial, we will install The R language and show how to add packages from the official Comprehensive The R language Archive Network (CThe R languageAN).&#8221;<\/p>\n<pre class=\"post-pre\"><code><\/code><\/pre>\n<p>Every occurrence of &#8216;R&#8217; has been substituted (including occurrences in &#8220;Comprehensive R Archive Network&#8221; and &#8220;CRAN&#8221;). The gsub() function identifies each word that matches the specified criterion and substitutes it with the provided word or values.<\/p>\n<h3>2. Employing the gsub() function with data frames<\/h3>\n<p>The gsub() function can also be used with data frames.<\/p>\n<pre class=\"post-pre\"><code><span class=\"token comment\"># creating a data frame<\/span>\r\ndf<span class=\"token operator\">&lt;-<\/span>data.frame<span class=\"token punctuation\">(<\/span>Creature<span class=\"token operator\">=<\/span>c<span class=\"token punctuation\">(<\/span><span class=\"token string\">'Starfish'<\/span><span class=\"token punctuation\">,<\/span><span class=\"token string\">'Blue Crab'<\/span><span class=\"token punctuation\">,<\/span><span class=\"token string\">'Bluefin Tuna'<\/span><span class=\"token punctuation\">,<\/span><span class=\"token string\">'Blue Shark'<\/span><span class=\"token punctuation\">,<\/span><span class=\"token string\">'Blue Whale'<\/span><span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">,<\/span>Population<span class=\"token operator\">=<\/span>c<span class=\"token punctuation\">(<\/span><span class=\"token number\">5<\/span><span class=\"token punctuation\">,<\/span><span class=\"token number\">6<\/span><span class=\"token punctuation\">,<\/span><span class=\"token number\">4<\/span><span class=\"token punctuation\">,<\/span><span class=\"token number\">2<\/span><span class=\"token punctuation\">,<\/span><span class=\"token number\">2<\/span><span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">)<\/span>\r\n<\/code><\/pre>\n<p>How about we start the values in the Creature column with &#8216;Deep Sea &#8216;?<\/p>\n<pre class=\"post-pre\"><code><span class=\"token comment\"># substituting the values<\/span>\r\ngsub<span class=\"token punctuation\">(<\/span><span class=\"token string\">'.*^'<\/span><span class=\"token punctuation\">,<\/span><span class=\"token string\">'Deep Sea '<\/span><span class=\"token punctuation\">,<\/span>df<span class=\"token operator\">$<\/span>Creature<span class=\"token punctuation\">)<\/span>\r\n<\/code><\/pre>\n<p>Executing this instruction yields the subsequent result.<\/p>\n<pre class=\"post-pre\"><code><\/code><\/pre>\n<div class=\"secondary-code-label\" title=\"Output\">Output<\/div>\n<pre class=\"post-pre\"><code><\/code><\/pre>\n<p>&#8220;Deep Sea Starfish&#8221; &#8220;Deep Sea Blue Crab&#8221; &#8220;Deep Sea Bluefin Tuna&#8221; &#8220;Deep Sea Blue Shark&#8221; &#8220;Deep Sea Blue Whale&#8221;<\/p>\n<pre class=\"post-pre\"><code><\/code><\/pre>\n<p>In this instance, the gsub() function employs the regex .*^, which represents the pattern indicating the beginning position of the string.<\/p>\n<h2>In summary, or To conclude<\/h2>\n<p>In this article, you have learned about the utilization of the sub() and gsub() functions in R. These functions allow you to replace a specific string or characters within a vector or data frame. The sub() function replaces only the first occurrence, while the gsub() function replaces all occurrences.<\/p>\n<p>Keep expanding your knowledge by learning about the application of the replace() function in R.<\/p>\n<p>&nbsp;<\/p>\n<p>More tutorials<\/p>\n<p><a class=\"LinkSuggestion__Link-sc-1gewdgc-4 cLBplk\" href=\"https:\/\/www.silicloud.com\/blog\/basics-plot-function-in-r\/\" target=\"_blank\" rel=\"noopener\">Basics of Graph Plotting &#8211; Comprehending the plot() Function in R<span class=\"sc-gswNZR eASTkv\">(Opens in a new browser tab)<\/span><\/a><\/p>\n<p><a class=\"LinkSuggestion__Link-sc-1gewdgc-4 cLBplk\" href=\"https:\/\/www.silicloud.com\/blog\/strsplit-function-in-r\/\" target=\"_blank\" rel=\"noopener\">strsplit function in R<span class=\"sc-gswNZR eASTkv\">(Opens in a new browser tab)<\/span><\/a><\/p>\n<p><a class=\"LinkSuggestion__Link-sc-1gewdgc-4 cLBplk\" href=\"https:\/\/www.silicloud.com\/blog\/the-command-design-pattern\/\" target=\"_blank\" rel=\"noopener\">The Command design pattern.<span class=\"sc-gswNZR eASTkv\">(Opens in a new browser tab)<\/span><\/a><\/p>\n<p><a class=\"LinkSuggestion__Link-sc-1gewdgc-4 cLBplk\" href=\"https:\/\/www.silicloud.com\/blog\/java-tutorial-for-beginners\/\" target=\"_blank\" rel=\"noopener\">Java Tutorial for beginners<span class=\"sc-gswNZR eASTkv\">(Opens in a new browser tab)<\/span><\/a><\/p>\n<p><a class=\"LinkSuggestion__Link-sc-1gewdgc-4 cLBplk\" href=\"https:\/\/www.silicloud.com\/blog\/the-java-language-implements-the-prototype-design-pattern\/\" target=\"_blank\" rel=\"noopener\">The Java language implements the Prototype Design Pattern.<span class=\"sc-gswNZR eASTkv\">(Opens in a new browser tab)<\/span><\/a><\/p>\n<p>&nbsp;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Here is one possible paraphrase of the introduction: &#8220;In this section, we will provide an introductory overview.&#8221; In R, the sub() and gsub() functions can be used to replace a string or characters in a vector or data frame with a designated string. These functions come in handy for making modifications on extensive sets of [&hellip;]<\/p>\n","protected":false},"author":9,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_import_markdown_pro_load_document_selector":0,"_import_markdown_pro_submit_text_textarea":"","footnotes":""},"categories":[1],"tags":[],"class_list":["post-563","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"yoast_head":"<!-- This site is optimized with the Yoast SEO Premium plugin v21.5 (Yoast SEO v21.5) - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>How to utilize sub() and gsub() functions in R - Blog - Silicon Cloud<\/title>\n<meta name=\"description\" content=\"In R, the sub() and gsub() functions can be used to replace a string or characters in a vector or data frame with a designated string.\" \/>\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.silicloud.com\/blog\/how-to-utilize-sub-and-gsub-functions-in-r\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"How to utilize sub() and gsub() functions in R\" \/>\n<meta property=\"og:description\" content=\"In R, the sub() and gsub() functions can be used to replace a string or characters in a vector or data frame with a designated string.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.silicloud.com\/blog\/how-to-utilize-sub-and-gsub-functions-in-r\/\" \/>\n<meta property=\"og:site_name\" content=\"Blog - Silicon Cloud\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/SiliCloudGlobal\/\" \/>\n<meta property=\"article:published_time\" content=\"2022-08-29T10:47:59+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2024-03-16T15:37:10+00:00\" \/>\n<meta name=\"author\" content=\"Ava Mitchell\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@SiliCloudGlobal\" \/>\n<meta name=\"twitter:site\" content=\"@SiliCloudGlobal\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Ava Mitchell\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"4 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\/\/www.silicloud.com\/blog\/how-to-utilize-sub-and-gsub-functions-in-r\/#article\",\"isPartOf\":{\"@id\":\"https:\/\/www.silicloud.com\/blog\/how-to-utilize-sub-and-gsub-functions-in-r\/\"},\"author\":{\"name\":\"Ava Mitchell\",\"@id\":\"https:\/\/www.silicloud.com\/blog\/#\/schema\/person\/a3e2658c2cb9fb2be95ae0a8861f4a64\"},\"headline\":\"How to utilize sub() and gsub() functions in R\",\"datePublished\":\"2022-08-29T10:47:59+00:00\",\"dateModified\":\"2024-03-16T15:37:10+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/www.silicloud.com\/blog\/how-to-utilize-sub-and-gsub-functions-in-r\/\"},\"wordCount\":819,\"commentCount\":0,\"publisher\":{\"@id\":\"https:\/\/www.silicloud.com\/blog\/#organization\"},\"inLanguage\":\"en-US\"},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/www.silicloud.com\/blog\/how-to-utilize-sub-and-gsub-functions-in-r\/\",\"url\":\"https:\/\/www.silicloud.com\/blog\/how-to-utilize-sub-and-gsub-functions-in-r\/\",\"name\":\"How to utilize sub() and gsub() functions in R - Blog - Silicon Cloud\",\"isPartOf\":{\"@id\":\"https:\/\/www.silicloud.com\/blog\/#website\"},\"datePublished\":\"2022-08-29T10:47:59+00:00\",\"dateModified\":\"2024-03-16T15:37:10+00:00\",\"description\":\"In R, the sub() and gsub() functions can be used to replace a string or characters in a vector or data frame with a designated string.\",\"breadcrumb\":{\"@id\":\"https:\/\/www.silicloud.com\/blog\/how-to-utilize-sub-and-gsub-functions-in-r\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/www.silicloud.com\/blog\/how-to-utilize-sub-and-gsub-functions-in-r\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/www.silicloud.com\/blog\/how-to-utilize-sub-and-gsub-functions-in-r\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/www.silicloud.com\/blog\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"How to utilize sub() and gsub() functions in R\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/www.silicloud.com\/blog\/#website\",\"url\":\"https:\/\/www.silicloud.com\/blog\/\",\"name\":\"Silicon Cloud Blog\",\"description\":\"\",\"publisher\":{\"@id\":\"https:\/\/www.silicloud.com\/blog\/#organization\"},\"inLanguage\":\"en-US\"},{\"@type\":\"Organization\",\"@id\":\"https:\/\/www.silicloud.com\/blog\/#organization\",\"name\":\"Silicon Cloud Blog\",\"url\":\"https:\/\/www.silicloud.com\/blog\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/www.silicloud.com\/blog\/#\/schema\/logo\/image\/\",\"url\":\"https:\/\/www.silicloud.com\/blog\/wp-content\/uploads\/2023\/11\/EN-SILICON-Full.png\",\"contentUrl\":\"https:\/\/www.silicloud.com\/blog\/wp-content\/uploads\/2023\/11\/EN-SILICON-Full.png\",\"width\":1024,\"height\":1024,\"caption\":\"Silicon Cloud Blog\"},\"image\":{\"@id\":\"https:\/\/www.silicloud.com\/blog\/#\/schema\/logo\/image\/\"},\"sameAs\":[\"https:\/\/www.facebook.com\/SiliCloudGlobal\/\",\"https:\/\/twitter.com\/SiliCloudGlobal\"]},{\"@type\":\"Person\",\"@id\":\"https:\/\/www.silicloud.com\/blog\/#\/schema\/person\/a3e2658c2cb9fb2be95ae0a8861f4a64\",\"name\":\"Ava Mitchell\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/www.silicloud.com\/blog\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/secure.gravatar.com\/avatar\/15c63cd0564b4a2e07d611bcdffa296f6ea80e8db07c3091f43a84010514899d?s=96&d=mm&r=g\",\"contentUrl\":\"https:\/\/secure.gravatar.com\/avatar\/15c63cd0564b4a2e07d611bcdffa296f6ea80e8db07c3091f43a84010514899d?s=96&d=mm&r=g\",\"caption\":\"Ava Mitchell\"},\"url\":\"https:\/\/www.silicloud.com\/blog\/author\/avamitchell\/\"}]}<\/script>\n<!-- \/ Yoast SEO Premium plugin. -->","yoast_head_json":{"title":"How to utilize sub() and gsub() functions in R - Blog - Silicon Cloud","description":"In R, the sub() and gsub() functions can be used to replace a string or characters in a vector or data frame with a designated string.","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.silicloud.com\/blog\/how-to-utilize-sub-and-gsub-functions-in-r\/","og_locale":"en_US","og_type":"article","og_title":"How to utilize sub() and gsub() functions in R","og_description":"In R, the sub() and gsub() functions can be used to replace a string or characters in a vector or data frame with a designated string.","og_url":"https:\/\/www.silicloud.com\/blog\/how-to-utilize-sub-and-gsub-functions-in-r\/","og_site_name":"Blog - Silicon Cloud","article_publisher":"https:\/\/www.facebook.com\/SiliCloudGlobal\/","article_published_time":"2022-08-29T10:47:59+00:00","article_modified_time":"2024-03-16T15:37:10+00:00","author":"Ava Mitchell","twitter_card":"summary_large_image","twitter_creator":"@SiliCloudGlobal","twitter_site":"@SiliCloudGlobal","twitter_misc":{"Written by":"Ava Mitchell","Est. reading time":"4 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/www.silicloud.com\/blog\/how-to-utilize-sub-and-gsub-functions-in-r\/#article","isPartOf":{"@id":"https:\/\/www.silicloud.com\/blog\/how-to-utilize-sub-and-gsub-functions-in-r\/"},"author":{"name":"Ava Mitchell","@id":"https:\/\/www.silicloud.com\/blog\/#\/schema\/person\/a3e2658c2cb9fb2be95ae0a8861f4a64"},"headline":"How to utilize sub() and gsub() functions in R","datePublished":"2022-08-29T10:47:59+00:00","dateModified":"2024-03-16T15:37:10+00:00","mainEntityOfPage":{"@id":"https:\/\/www.silicloud.com\/blog\/how-to-utilize-sub-and-gsub-functions-in-r\/"},"wordCount":819,"commentCount":0,"publisher":{"@id":"https:\/\/www.silicloud.com\/blog\/#organization"},"inLanguage":"en-US"},{"@type":"WebPage","@id":"https:\/\/www.silicloud.com\/blog\/how-to-utilize-sub-and-gsub-functions-in-r\/","url":"https:\/\/www.silicloud.com\/blog\/how-to-utilize-sub-and-gsub-functions-in-r\/","name":"How to utilize sub() and gsub() functions in R - Blog - Silicon Cloud","isPartOf":{"@id":"https:\/\/www.silicloud.com\/blog\/#website"},"datePublished":"2022-08-29T10:47:59+00:00","dateModified":"2024-03-16T15:37:10+00:00","description":"In R, the sub() and gsub() functions can be used to replace a string or characters in a vector or data frame with a designated string.","breadcrumb":{"@id":"https:\/\/www.silicloud.com\/blog\/how-to-utilize-sub-and-gsub-functions-in-r\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.silicloud.com\/blog\/how-to-utilize-sub-and-gsub-functions-in-r\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/www.silicloud.com\/blog\/how-to-utilize-sub-and-gsub-functions-in-r\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/www.silicloud.com\/blog\/"},{"@type":"ListItem","position":2,"name":"How to utilize sub() and gsub() functions in R"}]},{"@type":"WebSite","@id":"https:\/\/www.silicloud.com\/blog\/#website","url":"https:\/\/www.silicloud.com\/blog\/","name":"Silicon Cloud Blog","description":"","publisher":{"@id":"https:\/\/www.silicloud.com\/blog\/#organization"},"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/www.silicloud.com\/blog\/#organization","name":"Silicon Cloud Blog","url":"https:\/\/www.silicloud.com\/blog\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.silicloud.com\/blog\/#\/schema\/logo\/image\/","url":"https:\/\/www.silicloud.com\/blog\/wp-content\/uploads\/2023\/11\/EN-SILICON-Full.png","contentUrl":"https:\/\/www.silicloud.com\/blog\/wp-content\/uploads\/2023\/11\/EN-SILICON-Full.png","width":1024,"height":1024,"caption":"Silicon Cloud Blog"},"image":{"@id":"https:\/\/www.silicloud.com\/blog\/#\/schema\/logo\/image\/"},"sameAs":["https:\/\/www.facebook.com\/SiliCloudGlobal\/","https:\/\/twitter.com\/SiliCloudGlobal"]},{"@type":"Person","@id":"https:\/\/www.silicloud.com\/blog\/#\/schema\/person\/a3e2658c2cb9fb2be95ae0a8861f4a64","name":"Ava Mitchell","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.silicloud.com\/blog\/#\/schema\/person\/image\/","url":"https:\/\/secure.gravatar.com\/avatar\/15c63cd0564b4a2e07d611bcdffa296f6ea80e8db07c3091f43a84010514899d?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/15c63cd0564b4a2e07d611bcdffa296f6ea80e8db07c3091f43a84010514899d?s=96&d=mm&r=g","caption":"Ava Mitchell"},"url":"https:\/\/www.silicloud.com\/blog\/author\/avamitchell\/"}]}},"_links":{"self":[{"href":"https:\/\/www.silicloud.com\/blog\/wp-json\/wp\/v2\/posts\/563","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.silicloud.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.silicloud.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.silicloud.com\/blog\/wp-json\/wp\/v2\/users\/9"}],"replies":[{"embeddable":true,"href":"https:\/\/www.silicloud.com\/blog\/wp-json\/wp\/v2\/comments?post=563"}],"version-history":[{"count":0,"href":"https:\/\/www.silicloud.com\/blog\/wp-json\/wp\/v2\/posts\/563\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.silicloud.com\/blog\/wp-json\/wp\/v2\/media?parent=563"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.silicloud.com\/blog\/wp-json\/wp\/v2\/categories?post=563"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.silicloud.com\/blog\/wp-json\/wp\/v2\/tags?post=563"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}