{"id":75480,"date":"2020-01-14T12:36:33","date_gmt":"2020-01-14T07:06:33","guid":{"rendered":"https:\/\/techvidvan.com\/tutorials\/?p=75480"},"modified":"2020-01-14T12:36:33","modified_gmt":"2020-01-14T07:06:33","slug":"r-control-structures","status":"publish","type":"post","link":"https:\/\/techvidvan.com\/tutorials\/r-control-structures\/","title":{"rendered":"R Control Structures &#8211; Decision Making and Loops in R"},"content":{"rendered":"<p>There are a few control structures in R that help control the flow of the program. In R, there are decision<strong>-making structures<\/strong> like <strong>if-else<\/strong> that control execution of the program conditionally.<\/p>\n<p>There are also<strong> looping structures<\/strong> that loop or repeat code sections based on certain conditions and state.<\/p>\n<p>Today, we will take a look at these control structures that R provides and learn how to use them. So, without further ado, let\u2019s begin!<\/p>\n<h3>R Scripts<\/h3>\n<p>In the past tutorials, we have been using the console to run our code. While it may be easy to use, the console runs one line of code at a time. Therefore, we cannot run programs with multiple lines of code in the R-console. To solve this problem, we will write our code in R scripts and run them all at once.<\/p>\n<p>R scripts are text files with R code in them. They have an extension of <strong><code>.r<\/code><\/strong>. R scripts can be edited using any text editor.<\/p>\n<p>In this tutorial series, we will be using Rstudio to edit and run our R scripts.<\/p>\n<p>To run a part of your R file in Rstudio, select the code and press <strong>Ctrl+Enter<\/strong>.<\/p>\n<h2>Control Structures in R<\/h2>\n<p>R provides different control structures that can be used on their own and even in combinations to control the flow of the program. These control structures are:<\/p>\n<ol>\n<li>If &#8211; else<\/li>\n<li>ifelse() function<\/li>\n<li>Switch<\/li>\n<li>For loops<\/li>\n<li>While loops<\/li>\n<li>Break statement<\/li>\n<li>Next statement<\/li>\n<li>Repeat loops<\/li>\n<\/ol>\n<p>Let\u2019s take a look at these structures one at a time:<\/p>\n<h3>1. if &#8211; else<\/h3>\n<p>The <strong>if-else<\/strong> in R enforce <strong>conditional execution<\/strong> of code. They are an important part of R\u2019s decision-making capability. It allows us to make a decision based on the result of a condition. The <strong><code>if<\/code><\/strong> statement contains a condition that evaluates to a <strong>logical output<\/strong>. It runs the enclosed code block if the condition evaluates to <strong><code>TRUE<\/code><\/strong>. It skips the code block if the condition evaluates to <strong><code>FALSE<\/code><\/strong>.<\/p>\n<p>We can use the <strong><code>if<\/code><\/strong> statement on its own like:<\/p>\n<p><strong>Code:<\/strong><\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">a &lt;- 5\nb &lt;- 6\nif(a&lt;b){\n print(\"a is smaller than b\")\n}\n<\/pre>\n<p><strong>Output:<\/strong><\/p>\n<p><strong><a href=\"https:\/\/techvidvan.com\/tutorials\/wp-content\/uploads\/sites\/2\/2020\/01\/control-structures-in-r-if.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter wp-image-75483 size-full\" src=\"https:\/\/techvidvan.com\/tutorials\/wp-content\/uploads\/sites\/2\/2020\/01\/control-structures-in-r-if.png\" alt=\"if() - control structures in r\" width=\"1299\" height=\"740\" \/><\/a><\/strong><\/p>\n<p>You must check <a href=\"https:\/\/techvidvan.com\/tutorials\/r-data-types\/\"><strong>R Data Types<\/strong><\/a> as it plays a vital role in Control Structures.<\/p>\n<p>We use the <strong><code>else<\/code><\/strong> statement with the if statement to enact a choice between <strong>two alternatives<\/strong>. If the condition within the <strong><code>if<\/code><\/strong> statement evaluates to <strong><code>FALSE<\/code><\/strong>, it runs the code within the <strong><code>else<\/code><\/strong> statement. For example:<\/p>\n<p><strong>Code:<\/strong><\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">if(a&gt;b){\n  print(\"a is greater than b\")\n} else{\n  print(\"b is greater than a\")\n}<\/pre>\n<p><strong>Output:<\/strong><\/p>\n<p><strong><a href=\"https:\/\/techvidvan.com\/tutorials\/wp-content\/uploads\/sites\/2\/2020\/01\/control-structures-in-r-if-else.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter wp-image-75484 size-full\" src=\"https:\/\/techvidvan.com\/tutorials\/wp-content\/uploads\/sites\/2\/2020\/01\/control-structures-in-r-if-else.png\" alt=\"if-else - control structures in r \" width=\"1299\" height=\"741\" \/><\/a><\/strong><\/p>\n<p>We can use the <strong><code>else if<\/code><\/strong> statement to select between multiple options. For example:<\/p>\n<p><strong>Code:<\/strong><\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">a &lt;- 5\nb &lt;- 5\nif(a&lt;b){\n  print(\"a is smaller than b\")\n} else if(a==b) {\n  print(\"a is equal to b\")\n} else {\n  print(\"a is greater than b\")\n}<\/pre>\n<p><strong>Output:<\/strong><\/p>\n<p><a href=\"https:\/\/techvidvan.com\/tutorials\/wp-content\/uploads\/sites\/2\/2020\/01\/control-structures-in-r-else-if-1.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-75495\" src=\"https:\/\/techvidvan.com\/tutorials\/wp-content\/uploads\/sites\/2\/2020\/01\/control-structures-in-r-else-if-1.png\" alt=\" else if() - control structures in r\" width=\"1299\" height=\"742\" \/><\/a><\/p>\n<h3>2. ifelse() Function<\/h3>\n<p>The <strong><code>ifelse()<\/code><\/strong> function acts like the if-else structure. The following is the syntax of the <strong><code>ifelse()<\/code><\/strong> function in R:<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">ifelse(condition, exp_if_true, exp_if_false)<\/pre>\n<p>Where <strong><code>condition<\/code><\/strong> is the condition that evaluates to either <strong><code>TRUE<\/code><\/strong> or <strong><code>FALSE<\/code><\/strong>,<br \/>\n<strong><code>exp_if_true<\/code><\/strong> is the expression that is returned if the condition results in <strong><code>TRUE<\/code><\/strong>,<br \/>\n<strong><code>exp_if_false<\/code><\/strong> is the expression that is returned if the condition results in <strong><code>FALSE<\/code><\/strong>.<\/p>\n<p><strong>Code:<\/strong><\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">ifelse(a&lt;7,\"a is less than 7\",\"a is greater than 7\")<\/pre>\n<p><strong>Output:<\/strong><\/p>\n<p><strong><a href=\"https:\/\/techvidvan.com\/tutorials\/wp-content\/uploads\/sites\/2\/2020\/01\/control-structures-in-r-ifelse-function.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter wp-image-75487 size-full\" src=\"https:\/\/techvidvan.com\/tutorials\/wp-content\/uploads\/sites\/2\/2020\/01\/control-structures-in-r-ifelse-function.png\" alt=\"ifelse() function - control structures in r\" width=\"1299\" height=\"741\" \/><\/a><\/strong><\/p>\n<h3>3. switch<\/h3>\n<p>The <strong><code>switch<\/code><\/strong> is an easier way to choose between multiple alternatives than multiple if-else statements. The R switch takes a single input argument and executes a particular code based on the value of the input. Each possible value of the input is called a <strong>case<\/strong>. For example:<\/p>\n<p><strong>Code:<\/strong><\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">a &lt;- 4\nswitch(a,\n       \"1\"=\"this is the first case in switch\",\n       \"2\"=\"this is the second case in switch\",\n       \"3\"=\"this is the third case in switch\",\n       \"4\"=\"this is the fourth case in switch\",\n       \"5\"=\"this is the fifth case in switch\"\n       )<\/pre>\n<p><strong>Output:<\/strong><\/p>\n<p><strong><a href=\"https:\/\/techvidvan.com\/tutorials\/wp-content\/uploads\/sites\/2\/2020\/01\/control-structures-in-r-switch-.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter wp-image-75488 size-full\" src=\"https:\/\/techvidvan.com\/tutorials\/wp-content\/uploads\/sites\/2\/2020\/01\/control-structures-in-r-switch-.png\" alt=\"switch() - control structures in r\" width=\"1299\" height=\"741\" \/><\/a><\/strong><\/p>\n<h3>4. for loops<\/h3>\n<p>The <strong><code>for<\/code><\/strong> loop in R, repeats through sequences to perform repeated tasks. They work with an iterable variable to go through a sequence. The following is the syntax of for loops in R:<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">for(variable in sequence){\nCode_to_repeat\n}<\/pre>\n<p>Where <strong><code>variable<\/code><\/strong> is the iterative variable,<br \/>\n<strong><code>sequence<\/code><\/strong> is the sequence which we need to loop through,<br \/>\n<strong><code>Code_to_repeat<\/code><\/strong> is the code that runs every iteration.<\/p>\n<p><strong>Code:<\/strong><\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">vec &lt;- c(1:10)\nfor(i in vec){\n  print(vec[i])\n}<\/pre>\n<p><strong>Output:<\/strong><\/p>\n<p><strong><a href=\"https:\/\/techvidvan.com\/tutorials\/wp-content\/uploads\/sites\/2\/2020\/01\/control-structures-in-r-for-loop.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter wp-image-75489 size-full\" src=\"https:\/\/techvidvan.com\/tutorials\/wp-content\/uploads\/sites\/2\/2020\/01\/control-structures-in-r-for-loop.png\" alt=\"for loop - control structures in r\" width=\"1299\" height=\"741\" \/><\/a><\/strong><\/p>\n<h3>5. while Loops<\/h3>\n<p>The <strong><code>while<\/code><\/strong> loop in R evaluates a condition. If the condition evaluates to <strong><code>TRUE<\/code><\/strong> it loops through a code block, whereas if the condition evaluates to <strong><code>FALSE<\/code><\/strong> it exits the loop. The while loop in R keeps looping through the enclosed code block as long as the condition is <strong><code>TRUE<\/code><\/strong>. This can also result in an infinite loop sometimes which is something to avoid. The while loop\u2019s syntax is as follows:<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">while(condition){\ncode_to _run\n}<\/pre>\n<p>Where <strong><code>condition<\/code><\/strong> is the condition to run the <a href=\"https:\/\/cran.r-project.org\/doc\/manuals\/r-release\/R-intro.html#Loops-and-conditional-execution\">loop<\/a>,<br \/>\n<strong><code>code_to_run<\/code><\/strong> is the code block that runs if the condition evaluates to <strong><code>TRUE<\/code><\/strong>.<\/p>\n<p><strong>Code:<\/strong><\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">i &lt;- 0\nwhile(i&lt;10){\n  print(paste(\"this is iteration no\",i))\n  i &lt;- i+1\n}<\/pre>\n<p><strong>Output:<\/strong><\/p>\n<p><a href=\"https:\/\/techvidvan.com\/tutorials\/wp-content\/uploads\/sites\/2\/2020\/01\/control-structures-in-r-while-loop-1.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-75494\" src=\"https:\/\/techvidvan.com\/tutorials\/wp-content\/uploads\/sites\/2\/2020\/01\/control-structures-in-r-while-loop-1.png\" alt=\"while loop - control structures in r\" width=\"1299\" height=\"741\" \/><\/a><\/p>\n<h3>6. break Statement<\/h3>\n<p>The <strong><code>break<\/code><\/strong> statement can break out of a loop. Imagine a loop searching a specific element in a sequence. The loop needs to keep going until either it finds the element or until the end of the sequence. If it finds the element early,\u00a0 further looping is not needed. In such a case, the R break statement can \u201c<strong>break<\/strong>\u201d us out of the loop early. For example:<\/p>\n<p><strong>Code:<\/strong><\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">for(i in vec){\n  print(paste(\"this is iteration no \", i))\n  if(i==7){\n    print(\"break!!\")\n    break\n  }\n}<\/pre>\n<p><strong>Output:<\/strong><\/p>\n<h3><a href=\"https:\/\/techvidvan.com\/tutorials\/wp-content\/uploads\/sites\/2\/2020\/01\/control-structures-in-r-break-statement.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-75491\" src=\"https:\/\/techvidvan.com\/tutorials\/wp-content\/uploads\/sites\/2\/2020\/01\/control-structures-in-r-break-statement.png\" alt=\"break statement - control structures in r\" width=\"1299\" height=\"742\" \/><\/a><\/h3>\n<h3>7. next Statement<\/h3>\n<p>The <strong><code>next<\/code><\/strong> statement in R causes the loop to skip the current iteration and start the next one. For example:<\/p>\n<p><strong>Code:<\/strong><\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">for(i in vec){\n  if(i==5 || i==7){\n    print(\"next!!\")\n    next\n  }\n  print(paste(\"this is iteration no\", i))\n}<\/pre>\n<p><strong>Output:<\/strong><\/p>\n<p><strong><a href=\"https:\/\/techvidvan.com\/tutorials\/wp-content\/uploads\/sites\/2\/2020\/01\/control-structures-in-r-next-statement.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-75492\" src=\"https:\/\/techvidvan.com\/tutorials\/wp-content\/uploads\/sites\/2\/2020\/01\/control-structures-in-r-next-statement.png\" alt=\"next statement - control structures in r \" width=\"1299\" height=\"741\" \/><\/a><\/strong><\/p>\n<h3>8. repeat loop<\/h3>\n<p>The <strong><code>repeat<\/code><\/strong> loop in R initiates an infinite loop from the get-go. The only way to get out of the loop is to use the <strong><code>break<\/code><\/strong> statement. The repeat loop is useful when you don\u2019t know the required number of iterations. For example:<\/p>\n<p><strong>Code:<\/strong><\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">vec2 &lt;- 1:40\nx &lt;- 15\ni &lt;- 1\nrepeat{\n  if(i == x){\n    print(\"found it!!\")\n    break\n  }\n  print(\"not found!\")\n  i &lt;- i+1\n}<\/pre>\n<p><strong>Output:<\/strong><strong><a href=\"https:\/\/techvidvan.com\/tutorials\/wp-content\/uploads\/sites\/2\/2020\/01\/control-structures-in-r-repeat-loops.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-75493\" src=\"https:\/\/techvidvan.com\/tutorials\/wp-content\/uploads\/sites\/2\/2020\/01\/control-structures-in-r-repeat-loops.png\" alt=\"repeat loops - control structures in r \" width=\"1299\" height=\"741\" \/><\/a><\/strong><\/p>\n<h2>Summary<\/h2>\n<p>Decision-making is an important feature of any programming language. It allows you to change the sequence of execution of code based on certain conditions. Today, we studied the structures and statements that control the flow of an R program.<\/p>\n<p>These structures can be used in all combinations with each-other for different scenarios and implementations. The best way to learn more about their combinations and their results is to practice.<\/p>\n<p>If you find any difficulty while practicing R control structures, ask your doubts from <strong>TechVidvan<\/strong> Experts.<\/p>\n<p>Happy Coding!!<\/p>\n","protected":false},"excerpt":{"rendered":"<p>There are a few control structures in R that help control the flow of the program. In R, there are decision-making structures like if-else that control execution of the program conditionally. There are also&#46;&#46;&#46;<\/p>\n","protected":false},"author":1,"featured_media":75507,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1020],"tags":[1376,1377,1378,1379,1380,1381,1382,1383,1384],"class_list":["post-75480","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-r","tag-control-structures-in-r","tag-for-loop-in-r","tag-if-else-in-r","tag-ifelse-r","tag-next-r","tag-r-break","tag-r-switch","tag-repeat-loop-in-r","tag-while-loop-in-r"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v27.7 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>R Control Structures - Decision Making and Loops in R - TechVidvan<\/title>\n<meta name=\"description\" content=\"R provides different control structures that helps to control the flow of the program. Learn about R if-else conditionals, R loops and many more.\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/techvidvan.com\/tutorials\/r-control-structures\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"R Control Structures - Decision Making and Loops in R - TechVidvan\" \/>\n<meta property=\"og:description\" content=\"R provides different control structures that helps to control the flow of the program. Learn about R if-else conditionals, R loops and many more.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/techvidvan.com\/tutorials\/r-control-structures\/\" \/>\n<meta property=\"og:site_name\" content=\"TechVidvan\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/TechVidvan\/\" \/>\n<meta property=\"article:published_time\" content=\"2020-01-14T07:06:33+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/techvidvan.com\/tutorials\/wp-content\/uploads\/2020\/01\/control-structures-in-R.jpg\" \/>\n\t<meta property=\"og:image:width\" content=\"802\" \/>\n\t<meta property=\"og:image:height\" content=\"420\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/jpeg\" \/>\n<meta name=\"author\" content=\"TechVidvan Team\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@vidvantech\" \/>\n<meta name=\"twitter:site\" content=\"@vidvantech\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"TechVidvan Team\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"6 minutes\" \/>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"R Control Structures - Decision Making and Loops in R - TechVidvan","description":"R provides different control structures that helps to control the flow of the program. Learn about R if-else conditionals, R loops and many more.","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:\/\/techvidvan.com\/tutorials\/r-control-structures\/","og_locale":"en_US","og_type":"article","og_title":"R Control Structures - Decision Making and Loops in R - TechVidvan","og_description":"R provides different control structures that helps to control the flow of the program. Learn about R if-else conditionals, R loops and many more.","og_url":"https:\/\/techvidvan.com\/tutorials\/r-control-structures\/","og_site_name":"TechVidvan","article_publisher":"https:\/\/www.facebook.com\/TechVidvan\/","article_published_time":"2020-01-14T07:06:33+00:00","og_image":[{"width":802,"height":420,"url":"https:\/\/techvidvan.com\/tutorials\/wp-content\/uploads\/2020\/01\/control-structures-in-R.jpg","type":"image\/jpeg"}],"author":"TechVidvan Team","twitter_card":"summary_large_image","twitter_creator":"@vidvantech","twitter_site":"@vidvantech","twitter_misc":{"Written by":"TechVidvan Team","Est. reading time":"6 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/techvidvan.com\/tutorials\/r-control-structures\/#article","isPartOf":{"@id":"https:\/\/techvidvan.com\/tutorials\/r-control-structures\/"},"author":{"name":"TechVidvan Team","@id":"https:\/\/techvidvan.com\/tutorials\/#\/schema\/person\/e9c26e74dd3d87421f7ada9433b8cd22"},"headline":"R Control Structures &#8211; Decision Making and Loops in R","datePublished":"2020-01-14T07:06:33+00:00","mainEntityOfPage":{"@id":"https:\/\/techvidvan.com\/tutorials\/r-control-structures\/"},"wordCount":882,"commentCount":0,"publisher":{"@id":"https:\/\/techvidvan.com\/tutorials\/#organization"},"image":{"@id":"https:\/\/techvidvan.com\/tutorials\/r-control-structures\/#primaryimage"},"thumbnailUrl":"https:\/\/techvidvan.com\/tutorials\/wp-content\/uploads\/2020\/01\/control-structures-in-R.jpg","keywords":["Control Structures in R","for loop in R","if else in R","ifelse() R","next R","R break","R switch","repeat loop in R","while loop in R"],"articleSection":["R Tutorials"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/techvidvan.com\/tutorials\/r-control-structures\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/techvidvan.com\/tutorials\/r-control-structures\/","url":"https:\/\/techvidvan.com\/tutorials\/r-control-structures\/","name":"R Control Structures - Decision Making and Loops in R - TechVidvan","isPartOf":{"@id":"https:\/\/techvidvan.com\/tutorials\/#website"},"primaryImageOfPage":{"@id":"https:\/\/techvidvan.com\/tutorials\/r-control-structures\/#primaryimage"},"image":{"@id":"https:\/\/techvidvan.com\/tutorials\/r-control-structures\/#primaryimage"},"thumbnailUrl":"https:\/\/techvidvan.com\/tutorials\/wp-content\/uploads\/2020\/01\/control-structures-in-R.jpg","datePublished":"2020-01-14T07:06:33+00:00","description":"R provides different control structures that helps to control the flow of the program. Learn about R if-else conditionals, R loops and many more.","breadcrumb":{"@id":"https:\/\/techvidvan.com\/tutorials\/r-control-structures\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/techvidvan.com\/tutorials\/r-control-structures\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/techvidvan.com\/tutorials\/r-control-structures\/#primaryimage","url":"https:\/\/techvidvan.com\/tutorials\/wp-content\/uploads\/2020\/01\/control-structures-in-R.jpg","contentUrl":"https:\/\/techvidvan.com\/tutorials\/wp-content\/uploads\/2020\/01\/control-structures-in-R.jpg","width":802,"height":420,"caption":"control structures in R"},{"@type":"BreadcrumbList","@id":"https:\/\/techvidvan.com\/tutorials\/r-control-structures\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/techvidvan.com\/tutorials\/"},{"@type":"ListItem","position":2,"name":"R Control Structures &#8211; Decision Making and Loops in R"}]},{"@type":"WebSite","@id":"https:\/\/techvidvan.com\/tutorials\/#website","url":"https:\/\/techvidvan.com\/tutorials\/","name":"TechVidvan Blogs","description":"","publisher":{"@id":"https:\/\/techvidvan.com\/tutorials\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/techvidvan.com\/tutorials\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/techvidvan.com\/tutorials\/#organization","name":"TechVidvan","url":"https:\/\/techvidvan.com\/tutorials\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/techvidvan.com\/tutorials\/#\/schema\/logo\/image\/","url":"https:\/\/techvidvan.com\/tutorials\/wp-content\/uploads\/2024\/03\/techvidvan-logo-200x50-1.webp","contentUrl":"https:\/\/techvidvan.com\/tutorials\/wp-content\/uploads\/2024\/03\/techvidvan-logo-200x50-1.webp","width":200,"height":50,"caption":"TechVidvan"},"image":{"@id":"https:\/\/techvidvan.com\/tutorials\/#\/schema\/logo\/image\/"},"sameAs":["https:\/\/www.facebook.com\/TechVidvan\/","https:\/\/x.com\/vidvantech"]},{"@type":"Person","@id":"https:\/\/techvidvan.com\/tutorials\/#\/schema\/person\/e9c26e74dd3d87421f7ada9433b8cd22","name":"TechVidvan Team","description":"The TechVidvan Team delivers practical, beginner-friendly tutorials on programming, Java, Python, C++, DSA, AI, ML, data Science, Android, Flutter, MERN, Web Development, and technology. Our experts are here to help you upskill and excel in today\u2019s tech industry."}]}},"amp_enabled":true,"_links":{"self":[{"href":"https:\/\/techvidvan.com\/tutorials\/wp-json\/wp\/v2\/posts\/75480","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/techvidvan.com\/tutorials\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/techvidvan.com\/tutorials\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/techvidvan.com\/tutorials\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/techvidvan.com\/tutorials\/wp-json\/wp\/v2\/comments?post=75480"}],"version-history":[{"count":0,"href":"https:\/\/techvidvan.com\/tutorials\/wp-json\/wp\/v2\/posts\/75480\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/techvidvan.com\/tutorials\/wp-json\/wp\/v2\/media\/75507"}],"wp:attachment":[{"href":"https:\/\/techvidvan.com\/tutorials\/wp-json\/wp\/v2\/media?parent=75480"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/techvidvan.com\/tutorials\/wp-json\/wp\/v2\/categories?post=75480"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/techvidvan.com\/tutorials\/wp-json\/wp\/v2\/tags?post=75480"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}