{"id":188,"date":"2022-10-20T13:07:11","date_gmt":"2022-10-20T13:07:11","guid":{"rendered":"https:\/\/dorsu.edu.ph\/faculty\/jscabrera\/?page_id=188"},"modified":"2022-10-20T13:07:11","modified_gmt":"2022-10-20T13:07:11","slug":"r-operators","status":"publish","type":"page","link":"https:\/\/dorsu.edu.ph\/faculty\/jscabrera\/r-operators\/","title":{"rendered":"R&nbsp;Operators"},"content":{"rendered":"\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h2 class=\"wp-block-heading\">Operators<\/h2>\n\n\n\n<p>Operators are used to perform operations on variables and values.<\/p>\n\n\n\n<p>In the example below, we use the&nbsp;<code>+<\/code>&nbsp;operator to add together two values:<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Example<\/h3>\n\n\n\n<pre class=\"wp-block-code\"><code>10 + 5<\/code><\/pre>\n\n\n\n<p>R divides the operators in the following groups:<\/p>\n\n\n\n<ul class=\"wp-block-list\"><li>Arithmetic operators<\/li><li>Assignment operators<\/li><li>Comparison operators<\/li><li>Logical operators<\/li><li>Miscellaneous operators<\/li><\/ul>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h2 class=\"wp-block-heading\">R Arithmetic Operators<\/h2>\n\n\n\n<p>Arithmetic operators are used with numeric values to perform common mathematical operations:<\/p>\n\n\n\n<figure class=\"wp-block-table\"><table><tbody><tr><th>Operator<\/th><th>Name<\/th><th>Example<\/th><th>Try it<\/th><\/tr><tr><td>+<\/td><td>Addition<\/td><td>x + y<\/td><td><a target=\"_blank\" href=\"https:\/\/www.w3schools.com\/r\/tryr.asp?filename=demo_oper_add\" rel=\"noreferrer noopener\">Try it \u00bb<\/a><\/td><\/tr><tr><td>&#8211;<\/td><td>Subtraction<\/td><td>x &#8211; y<\/td><td><a target=\"_blank\" href=\"https:\/\/www.w3schools.com\/r\/tryr.asp?filename=demo_oper_sub\" rel=\"noreferrer noopener\">Try it \u00bb<\/a><\/td><\/tr><tr><td>*<\/td><td>Multiplication<\/td><td>x * y<\/td><td><a target=\"_blank\" href=\"https:\/\/www.w3schools.com\/r\/tryr.asp?filename=demo_oper_mult\" rel=\"noreferrer noopener\">Try it \u00bb<\/a><\/td><\/tr><tr><td>\/<\/td><td>Division<\/td><td>x \/ y<\/td><td><a target=\"_blank\" href=\"https:\/\/www.w3schools.com\/r\/tryr.asp?filename=demo_oper_div\" rel=\"noreferrer noopener\">Try it \u00bb<\/a><\/td><\/tr><tr><td>^<\/td><td>Exponent<\/td><td>x ^ y<\/td><td><a target=\"_blank\" href=\"https:\/\/www.w3schools.com\/r\/tryr.asp?filename=demo_oper_exp\" rel=\"noreferrer noopener\">Try it \u00bb<\/a><\/td><\/tr><tr><td>%%<\/td><td>Modulus (Remainder from division)<\/td><td>x %% y<\/td><td><a target=\"_blank\" href=\"https:\/\/www.w3schools.com\/r\/tryr.asp?filename=demo_oper_mod\" rel=\"noreferrer noopener\">Try it \u00bb<\/a><\/td><\/tr><tr><td>%\/%<\/td><td>Integer Division<\/td><td>x%\/%y<\/td><td><a target=\"_blank\" href=\"https:\/\/www.w3schools.com\/r\/tryr.asp?filename=demo_oper_int_div\" rel=\"noreferrer noopener\">Try it \u00bb<\/a><\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h2 class=\"wp-block-heading\">R Assignment Operators<\/h2>\n\n\n\n<p>Assignment operators are used to assign values to variables:<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Example<\/h3>\n\n\n\n<pre class=\"wp-block-code\"><code>my_var &lt;- 3\nmy_var &lt;&lt;- 3\n3 -> my_var\n3 ->> my_var\nmy_var # print my_var<\/code><\/pre>\n\n\n\n<p>It is also possible to turn the direction of the assignment operator.<\/p>\n\n\n\n<p>x &lt;- 3 is equal to 3 -&gt; x<\/p>\n\n\n\n<p>ADVERTISEMENT<\/p>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h2 class=\"wp-block-heading\">R Comparison Operators<\/h2>\n\n\n\n<p>Comparison operators are used to compare two values:<\/p>\n\n\n\n<figure class=\"wp-block-table\"><table><tbody><tr><th>Operator<\/th><th>Name<\/th><th>Example<\/th><th>Try it<\/th><\/tr><tr><td>==<\/td><td>Equal<\/td><td>x == y<\/td><td><a target=\"_blank\" href=\"https:\/\/www.w3schools.com\/r\/tryr.asp?filename=demo_oper_compare1\" rel=\"noreferrer noopener\">Try it \u00bb<\/a><\/td><\/tr><tr><td>!=<\/td><td>Not equal<\/td><td>x != y<\/td><td><a target=\"_blank\" href=\"https:\/\/www.w3schools.com\/r\/tryr.asp?filename=demo_oper_compare2\" rel=\"noreferrer noopener\">Try it \u00bb<\/a><\/td><\/tr><tr><td>&gt;<\/td><td>Greater than<\/td><td>x &gt; y<\/td><td><a target=\"_blank\" href=\"https:\/\/www.w3schools.com\/r\/tryr.asp?filename=demo_oper_compare4\" rel=\"noreferrer noopener\">Try it \u00bb<\/a><\/td><\/tr><tr><td>&lt;<\/td><td>Less than<\/td><td>x &lt; y<\/td><td><a target=\"_blank\" href=\"https:\/\/www.w3schools.com\/r\/tryr.asp?filename=demo_oper_compare5\" rel=\"noreferrer noopener\">Try it \u00bb<\/a><\/td><\/tr><tr><td>&gt;=<\/td><td>Greater than or equal to<\/td><td>x &gt;= y<\/td><td><a target=\"_blank\" href=\"https:\/\/www.w3schools.com\/r\/tryr.asp?filename=demo_oper_compare6\" rel=\"noreferrer noopener\">Try it \u00bb<\/a><\/td><\/tr><tr><td>&lt;=<\/td><td>Less than or equal to<\/td><td>x &lt;= y<\/td><td><a target=\"_blank\" href=\"https:\/\/www.w3schools.com\/r\/tryr.asp?filename=demo_oper_compare7\" rel=\"noreferrer noopener\">Try it \u00bb<\/a><\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h2 class=\"wp-block-heading\">R Logical Operators<\/h2>\n\n\n\n<p>Logical operators are used to combine conditional statements:<\/p>\n\n\n\n<figure class=\"wp-block-table\"><table><tbody><tr><th>Operator<\/th><th>Description<\/th><\/tr><tr><td>&amp;<\/td><td>Element-wise Logical AND operator. It returns TRUE if both elements are TRUE<\/td><\/tr><tr><td>&amp;&amp;<\/td><td>Logical AND operator &#8211; Returns TRUE if both statements are TRUE<\/td><\/tr><tr><td>|<\/td><td>Elementwise- Logical OR operator. It returns TRUE if one of the statement is TRUE<\/td><\/tr><tr><td>||<\/td><td>Logical OR operator. It returns TRUE if one of the statement is TRUE.<\/td><\/tr><tr><td>!<\/td><td>Logical NOT &#8211; returns FALSE if statement is TRUE<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h2 class=\"wp-block-heading\">R Miscellaneous Operators<\/h2>\n\n\n\n<p>Miscellaneous operators are used to manipulate data:<\/p>\n\n\n\n<figure class=\"wp-block-table\"><table><tbody><tr><th>Operator<\/th><th>Description<\/th><th>Example<\/th><\/tr><tr><td>:<\/td><td>Creates a series of numbers in a sequence<\/td><td>x &lt;- 1:10<\/td><\/tr><tr><td>%in%<\/td><td>Find out if an element belongs to a vector<\/td><td>x %in% y<\/td><\/tr><tr><td>%*%<\/td><td>Matrix Multiplication<\/td><td>x &lt;- Matrix1 %*% Matrix2<\/td><\/tr><\/tbody><\/table><\/figure>\n","protected":false},"excerpt":{"rendered":"<p>Operators Operators are used to perform operations on variables and values. In the example below, we use the&nbsp;+&nbsp;operator to add together two values: Example R divides the operators in the following groups: Arithmetic operators Assignment operators Comparison operators Logical operators&#8230;<br \/><a class=\"read-more-button\" href=\"https:\/\/dorsu.edu.ph\/faculty\/jscabrera\/r-operators\/\">Read more<\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"parent":0,"menu_order":0,"comment_status":"closed","ping_status":"closed","template":"","meta":{"footnotes":""},"class_list":["post-188","page","type-page","status-publish","hentry"],"_links":{"self":[{"href":"https:\/\/dorsu.edu.ph\/faculty\/jscabrera\/wp-json\/wp\/v2\/pages\/188","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/dorsu.edu.ph\/faculty\/jscabrera\/wp-json\/wp\/v2\/pages"}],"about":[{"href":"https:\/\/dorsu.edu.ph\/faculty\/jscabrera\/wp-json\/wp\/v2\/types\/page"}],"author":[{"embeddable":true,"href":"https:\/\/dorsu.edu.ph\/faculty\/jscabrera\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/dorsu.edu.ph\/faculty\/jscabrera\/wp-json\/wp\/v2\/comments?post=188"}],"version-history":[{"count":1,"href":"https:\/\/dorsu.edu.ph\/faculty\/jscabrera\/wp-json\/wp\/v2\/pages\/188\/revisions"}],"predecessor-version":[{"id":189,"href":"https:\/\/dorsu.edu.ph\/faculty\/jscabrera\/wp-json\/wp\/v2\/pages\/188\/revisions\/189"}],"wp:attachment":[{"href":"https:\/\/dorsu.edu.ph\/faculty\/jscabrera\/wp-json\/wp\/v2\/media?parent=188"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}