{"id":764,"date":"2018-05-16T13:19:20","date_gmt":"2018-05-16T11:19:20","guid":{"rendered":"https:\/\/blogs.fu-berlin.de\/reseda\/?page_id=764"},"modified":"2018-09-25T10:26:21","modified_gmt":"2018-09-25T08:26:21","slug":"e01","status":"publish","type":"page","link":"https:\/\/blogs.fu-berlin.de\/reseda\/e01\/","title":{"rendered":"R &#8211; Exercise I"},"content":{"rendered":"<p>Welcome to your first training session!<br \/>\nNo need to be nervous: this page contains not only tasks, but also their solutions as folded code elements. You can unfold these code blocks by simply clicking on them. Give it a try:<\/p>\n<pre class=\"theme:amityreseda minimize:true\" title=\"Example: show code\">\r\n# Well done!\r\n\r\n# Spoiler! -  you will find your answer here\r\n<\/pre>\n<p>1) Create a variable called <span class=\"crayon-inline\">a<\/span> and assign the number <em>2017<\/em> to it!<\/p>\n<pre class=\"theme:amityreseda minimize:true\" title=\"show code\">\r\n# use the \"&lt;-&quot; operator for variable assignments:\r\na &lt;- 2017\r\n<\/pre>\n<p>2) Calculate the square root of 1089 and save the result in variable <span class=\"crayon-inline\">b<\/span>!<\/p>\n<pre class=\"theme:amityreseda minimize:true\" title=\"show code\">\r\n# use the built- in function \"sqrt()\" and the number 1089 as an argument:\r\nb &lt;- sqrt(1089)\r\n<\/pre>\n<p>3) Calculate the sum of <span class=\"crayon-inline\">a<\/span> and <span class=\"crayon-inline\">b<\/span>!<\/p>\n<pre class=\"theme:amityreseda minimize:true\" title=\"show code\">\r\n# done via standard operators:\r\na + b\r\n## [1] 2050\r\n<\/pre>\n<p>4) Overwrite variable <span class=\"crayon-inline\">a<\/span> by assigning the value 2018 to it!<\/p>\n<pre class=\"theme:amityreseda minimize:true\" title=\"show code\">\r\n# simply assign a new value to an existing variable in order to overwrite it\r\na &lt;- 2018\r\n<\/pre>\n<p>5) Make a copy of variable <span class=\"crayon-inline\">b<\/span> and name it <span class=\"crayon-inline\">c<\/span>!<\/p>\n<pre class=\"theme:amityreseda minimize:true\" title=\"show code\">\r\n# variable assignment works from right (existing variable) to left (new variable):\r\nc &lt;- b\r\n<\/pre>\n<p>6) Create your own function called <span class=\"crayon-inline\">my.fun()<\/span>, which requires three variables as input. The function should generate the square root of the product of all three variables and return one numeric value!<\/p>\n<pre class=\"theme:amityreseda minimize:true\" title=\"show code\">\r\nmy.fun &lt;- function( var1, var2, var3 ) {\r\n  result &lt;- sqrt( var1 * var2 * var3 )\r\n  return(result)\r\n}\r\n<\/pre>\n<p>7) Use <span class=\"crayon-inline\">a<\/span>, <span class=\"crayon-inline\">b<\/span> and <span class=\"crayon-inline\">c<\/span> (from the previous tasks) as input into <span class=\"crayon-inline\">my.fun()<\/span> and save the output to variable <span class=\"crayon-inline\">d<\/span>! Check the resulting value!<\/p>\n<pre class=\"theme:amityreseda minimize:true\" title=\"show code\">\r\nd &lt;- my.fun(a, b, c)\r\nd\r\n## [1] 1482.431\r\n<\/pre>\n<p>&nbsp;<\/p>\n<hr style=\"height: 4px;background-color: #6b9e1f\" \/>\n<a href=\"https:\/\/blogs.fu-berlin.de\/reseda\/r-crash-course-2\/\"><br \/>\n<button style=\"width:100%;text-align:right;padding: 10 0;background-color:white;margin:-55px 0 0 0\"><\/p>\n<div style=\"font-family: 'Noto Sans',sans-serif;line-height: 1.2\">\n<span style=\"font-size: 30px;color:#6b9e1f\"><strong><em>Return to R Crash Course <\/em><\/strong><\/span>\n<\/div>\n<p><\/button><\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Welcome to your first training session! No need to be nervous: this page contains not only tasks, but also their solutions as folded code elements. You can unfold these code blocks by simply clicking on them. Give it a try: # Well done! # Spoiler! &#8211; you will find your answer here 1) Create a &hellip; <a href=\"https:\/\/blogs.fu-berlin.de\/reseda\/e01\/\" class=\"more-link\">Continue reading<span class=\"screen-reader-text\"> &#8220;R &#8211; Exercise I&#8221;<\/span><\/a><\/p>\n","protected":false},"author":3237,"featured_media":0,"parent":0,"menu_order":0,"comment_status":"closed","ping_status":"closed","template":"","meta":{"footnotes":""},"class_list":["post-764","page","type-page","status-publish","hentry"],"_links":{"self":[{"href":"https:\/\/blogs.fu-berlin.de\/reseda\/wp-json\/wp\/v2\/pages\/764","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/blogs.fu-berlin.de\/reseda\/wp-json\/wp\/v2\/pages"}],"about":[{"href":"https:\/\/blogs.fu-berlin.de\/reseda\/wp-json\/wp\/v2\/types\/page"}],"author":[{"embeddable":true,"href":"https:\/\/blogs.fu-berlin.de\/reseda\/wp-json\/wp\/v2\/users\/3237"}],"replies":[{"embeddable":true,"href":"https:\/\/blogs.fu-berlin.de\/reseda\/wp-json\/wp\/v2\/comments?post=764"}],"version-history":[{"count":20,"href":"https:\/\/blogs.fu-berlin.de\/reseda\/wp-json\/wp\/v2\/pages\/764\/revisions"}],"predecessor-version":[{"id":2468,"href":"https:\/\/blogs.fu-berlin.de\/reseda\/wp-json\/wp\/v2\/pages\/764\/revisions\/2468"}],"wp:attachment":[{"href":"https:\/\/blogs.fu-berlin.de\/reseda\/wp-json\/wp\/v2\/media?parent=764"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}