{"id":1770,"date":"2016-08-14T14:11:27","date_gmt":"2016-08-14T13:11:27","guid":{"rendered":"http:\/\/pcool.dyndns.org:8080\/statsbook\/?page_id=1770"},"modified":"2025-06-23T17:52:31","modified_gmt":"2025-06-23T16:52:31","slug":"objects-and-operators","status":"publish","type":"page","link":"https:\/\/pcool.dyndns.org\/index.php\/objects-and-operators\/","title":{"rendered":"Objects and Operators"},"content":{"rendered":"\n<p><strong>Objects in R<\/strong><\/p>\n\n\n\n<p><em><strong>Vector:<\/strong><\/em> one dimensional array; the elements all have the same type<\/p>\n\n\n\n<pre class=\"wp-block-code has-small-font-size\"><code><em><span style=\"color: #ff0000;\">my_vector &lt;- c(1,2,3,4,5)<\/span><\/em>\n<em> <span style=\"color: #ff0000;\">my_vector<\/span><\/em>\n<em><span style=\"color: #0000ff;\">&#91;1] 1 2 3 4 5<\/span><\/em><\/code><\/pre>\n\n\n\n<p><em><strong>Matrix<\/strong>: <\/em>two dimensions of same type; ie <em>matrix(c(1:9),byrow = TRUE, nrow = 3)<\/em> )<\/p>\n\n\n\n<pre class=\"wp-block-code has-small-font-size\"><code><span style=\"color: #ff0000;\"><em>my_matrix &lt;- matrix(c(1,2,3,4,5,6,7,8,9), byrow = TRUE, nrow = 3)<\/em><\/span>\n<span style=\"color: #ff0000;\"><em>my_matrix<\/em><\/span>\n<span style=\"color: #0000ff;\"><em>\u00a0\u00a0\u00a0\u00a0 &#91;,1] &#91;,2] &#91;,3]<\/em><\/span>\n<span style=\"color: #0000ff;\"><em>&#91;1,]\u00a0\u00a0\u00a0 1\u00a0\u00a0\u00a0 2\u00a0\u00a0\u00a0 3<\/em><\/span>\n<span style=\"color: #0000ff;\"><em>&#91;2,]\u00a0\u00a0\u00a0 4\u00a0\u00a0\u00a0 5\u00a0\u00a0\u00a0 6<\/em><\/span>\n<span style=\"color: #0000ff;\"><em>&#91;3,]\u00a0\u00a0\u00a0 7\u00a0\u00a0\u00a0 8\u00a0\u00a0\u00a0 9<\/em><\/span><\/code><\/pre>\n\n\n\n<p>or:<\/p>\n\n\n\n<pre class=\"wp-block-code has-small-font-size\"><code><span style=\"color: #ff0000;\"><em>my_matrix &lt;- matrix(c(1:9), byrow = TRUE, nrow = 3)<\/em><\/span>\n<span style=\"color: #ff0000;\"><em>my_matrix<\/em><\/span>\n<span style=\"color: #0000ff;\"><em>\u00a0\u00a0\u00a0\u00a0 &#91;,1] &#91;,2] &#91;,3]<\/em><\/span>\n<span style=\"color: #0000ff;\"><em>&#91;1,]\u00a0\u00a0\u00a0 1\u00a0\u00a0\u00a0 2\u00a0\u00a0\u00a0 3<\/em><\/span>\n<span style=\"color: #0000ff;\"><em>&#91;2,]\u00a0\u00a0\u00a0 4\u00a0\u00a0\u00a0 5\u00a0\u00a0\u00a0 6<\/em><\/span>\n<span style=\"color: #0000ff;\"><em>&#91;3,]\u00a0\u00a0\u00a0 7\u00a0\u00a0\u00a0 8\u00a0\u00a0\u00a0 9<\/em><\/span><\/code><\/pre>\n\n\n\n<p><em><strong>Data frame<\/strong> <\/em>could contain different data types in different columns<\/p>\n\n\n\n<p><em><strong>List<\/strong><\/em> can contain combinations of dataframes, vectors other lists etc<\/p>\n\n\n\n<p><strong>Factors<\/strong><\/p>\n\n\n\n<p><em>to be added<\/em><\/p>\n\n\n\n<p><strong>Operators in R<\/strong><\/p>\n\n\n\n<p><em>to be added<\/em><\/p>\n\n\n\n<p><strong>R operators:<\/strong><\/p>\n\n\n\n<p><strong>Arithmetic operators<\/strong><\/p>\n\n\n\n<p>&lt;-&nbsp;&nbsp; =&nbsp; (ie x&lt;-5 define x as number 5)<\/p>\n\n\n\n<p>+&nbsp;&nbsp; addition (ie: 5+2=7)<\/p>\n\n\n\n<p>&#8211;&nbsp; subtraction (ie 5-2=3)<\/p>\n\n\n\n<p>*&nbsp;&nbsp; multiplication (ie 5*3=15)<\/p>\n\n\n\n<p>\/&nbsp;&nbsp; division (ie 6\/3=2)<\/p>\n\n\n\n<p>^&nbsp;&nbsp; exponent (ie 5^2=25)<\/p>\n\n\n\n<p>x %% y&nbsp;&nbsp; modulus (ie 5%%3 =2)<\/p>\n\n\n\n<p>x %\/% y integer division (ie 5%\/%3=1)<\/p>\n\n\n\n<p><strong>Logical operators<\/strong><\/p>\n\n\n\n<p>&lt;&nbsp;&nbsp; Less than<\/p>\n\n\n\n<p>&lt;=&nbsp;&nbsp; less than or equal to<\/p>\n\n\n\n<p>&gt;&nbsp;&nbsp; more than<\/p>\n\n\n\n<p>&gt;=&nbsp;&nbsp; more than or equal to<\/p>\n\n\n\n<p>==&nbsp;&nbsp; is equal to<\/p>\n\n\n\n<p>!&nbsp;&nbsp; not<\/p>\n\n\n\n<p>&amp;&nbsp;&nbsp; and<\/p>\n\n\n\n<p>|&nbsp;&nbsp; or<\/p>\n\n\n\n<p>isTRUE(x)&nbsp;&nbsp; is x true?&nbsp; (<span style=\"color: #ff0000;\"><span style=\"color: #000000;\">ie<\/span> isTRUE(5&lt;4)<span style=\"color: #000000;\">,<\/span><em>&nbsp;<\/em><\/span> <em><span style=\"color: #0000ff;\">FALSE<\/span><\/em>)<\/p>\n\n\n\n<p>is.na(x)&nbsp;&nbsp; is &#8216;not available&#8217; (NA) (ie <span style=\"color: #ff0000;\">x&lt;-5<span style=\"color: #000000;\">,<\/span><em> is.na(x)<\/em><span style=\"color: #000000;\">,<\/span><\/span> <em><span style=\"color: #0000ff;\">FALSE<span style=\"color: #000000;\">)<\/span><\/span><\/em><\/p>\n\n\n\n<p>!(is.na(x))&nbsp;&nbsp; is not &#8216;not available (NA) (ie <span style=\"color: #ff0000;\"><em>x&lt;-5<\/em><\/span>,<em><span style=\"color: #ff0000;\"> !(is.na(x))<\/span><\/em>, <span style=\"color: #0000ff;\">TRUE<\/span><em>)<\/em><\/p>\n\n\n\n<p>ifelse(test, yes, no)&nbsp; if test condition is true &#8216;yes&#8217;, otherwise &#8216;no&#8217;<\/p>\n\n\n\n<p><strong>Relational Operators<\/strong><\/p>\n\n\n\n<p><em>types and examples<\/em><\/p>\n\n\n\n<p><strong>Logical Operators<\/strong><\/p>\n\n\n\n<p><em>types and examples<\/em><\/p>\n\n\n\n<p><strong>Conditional Operators<\/strong><\/p>\n\n\n\n<p><em>types and examples<\/em><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Objects in R Vector: one dimensional array; the elements all have the same type Matrix: two dimensions of same type; ie matrix(c(1:9),byrow = TRUE, nrow = 3) ) or: Data frame could contain different data types in different columns List can contain combinations of dataframes, vectors other lists etc Factors to be added Operators in [&hellip;]<\/p>\n","protected":false},"author":2,"featured_media":0,"parent":0,"menu_order":0,"comment_status":"closed","ping_status":"closed","template":"","meta":{"inline_featured_image":false,"footnotes":""},"class_list":["post-1770","page","type-page","status-publish","hentry"],"_links":{"self":[{"href":"https:\/\/pcool.dyndns.org\/index.php\/wp-json\/wp\/v2\/pages\/1770","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/pcool.dyndns.org\/index.php\/wp-json\/wp\/v2\/pages"}],"about":[{"href":"https:\/\/pcool.dyndns.org\/index.php\/wp-json\/wp\/v2\/types\/page"}],"author":[{"embeddable":true,"href":"https:\/\/pcool.dyndns.org\/index.php\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/pcool.dyndns.org\/index.php\/wp-json\/wp\/v2\/comments?post=1770"}],"version-history":[{"count":2,"href":"https:\/\/pcool.dyndns.org\/index.php\/wp-json\/wp\/v2\/pages\/1770\/revisions"}],"predecessor-version":[{"id":4293,"href":"https:\/\/pcool.dyndns.org\/index.php\/wp-json\/wp\/v2\/pages\/1770\/revisions\/4293"}],"wp:attachment":[{"href":"https:\/\/pcool.dyndns.org\/index.php\/wp-json\/wp\/v2\/media?parent=1770"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}