{"id":475,"date":"2018-07-16T04:41:33","date_gmt":"2018-07-16T04:41:33","guid":{"rendered":"http:\/\/itp7.epgpbooks.inflibnet.ac.in\/?post_type=chapter&#038;p=475"},"modified":"2019-05-16T09:35:41","modified_gmt":"2019-05-16T09:35:41","slug":"r-programming-2","status":"publish","type":"chapter","link":"https:\/\/ebooks.inflibnet.ac.in\/itp7\/chapter\/r-programming-2\/","title":{"rendered":"R Programming &#8211; 2"},"content":{"raw":"<div><span style=\"float: right;\"><a href=\"https:\/\/youtu.be\/r9PcMwmVkFo\" target=\"_blank\" rel=\"noopener\"><img src=\"http:\/\/epgpbooks.inflibnet.ac.in\/wp-content\/uploads\/2018\/11\/download.png\" alt=\"epgp books\" width=\"75px\" height=\"75px;\" \/><\/a>\r\n<\/span><\/div>\r\n&nbsp;\r\n\r\n<strong>Writing Scripts<\/strong>\r\n\r\n&nbsp;\r\n<p style=\"text-align: justify;\">In the previous module of R programming - 1, we had studied the capabilities provide by R Environment. We had seen the use of variables, operators, data structures and datasets in R. In this module, we will study how to write programs in R. This module will cover the basic programming constructs provided by R environment. Let us begin our study by typing a simple program that performs addition calculation. The following code performs addition of subject marks of 3 different subjects. Further, it calculates the percentage and is displayed on screen.<\/p>\r\n&nbsp;\r\n<p style=\"text-align: center;\"><img class=\"size-full wp-image-476 aligncenter\" src=\"http:\/\/itp7.epgpbooks.inflibnet.ac.in\/wp-content\/uploads\/sites\/30\/2018\/07\/1-4.png\" alt=\"\" width=\"584\" height=\"157\" \/><\/p>\r\n<p style=\"text-align: justify;\">Rather than typing the program in a text editor and executing it from command prompt, we can use GUI to make the tasks easier. RStudio is a free GUI available for R programming. The following is a screen shot of RStudio:<\/p>\r\n<p style=\"text-align: center;\"><img class=\"size-full wp-image-477 aligncenter\" src=\"http:\/\/itp7.epgpbooks.inflibnet.ac.in\/wp-content\/uploads\/sites\/30\/2018\/07\/2-3.jpg\" alt=\"\" width=\"1366\" height=\"730\" \/><\/p>\r\n<p style=\"text-align: center;\">Figure 1: Rstudio - GUI for R programming<\/p>\r\n&nbsp;\r\n<p style=\"text-align: justify;\">As you can see in the GUI, there are 4 panels, there is an editor to type the programs, the output of which is seen in console at the bottom of editor. There is also a watch windows to observe the values of variables while the programming is running. The panel provided in bottom right corner lists files of the directory, packages installed in R, it can also be used to view plots or to browse help.<\/p>\r\n&nbsp;\r\n\r\n<strong>Decision Making<\/strong>\r\n\r\n&nbsp;\r\n<p style=\"text-align: justify;\">As in other programming languages, R supports decision making facilities like if statements.<\/p>\r\nThe syntax of if statement is as below:\r\n<p style=\"text-align: center;\"><img class=\"size-full wp-image-478 aligncenter\" src=\"http:\/\/itp7.epgpbooks.inflibnet.ac.in\/wp-content\/uploads\/sites\/30\/2018\/07\/3-3.png\" alt=\"\" width=\"581\" height=\"153\" \/><\/p>\r\n<p style=\"text-align: justify;\">We must be careful while using if statement, since the closing parenthesis '}' and else keyword must be in the same line. Let us see a sample program that uses decision making. The following example checks whether a number is negative or positive number and display accordingly:<\/p>\r\n<p style=\"text-align: center;\"><img class=\"size-full wp-image-479 aligncenter\" src=\"http:\/\/itp7.epgpbooks.inflibnet.ac.in\/wp-content\/uploads\/sites\/30\/2018\/07\/4-3.png\" alt=\"\" width=\"578\" height=\"112\" \/><\/p>\r\n<strong>Looping in R<\/strong>\r\n\r\n&nbsp;\r\n<p style=\"text-align: justify;\">R supports looping construct in the form of while loop and for loops. The syntax of while loop is as shown below:<\/p>\r\n<p style=\"text-align: center;\"><img class=\"size-full wp-image-480 aligncenter\" src=\"http:\/\/itp7.epgpbooks.inflibnet.ac.in\/wp-content\/uploads\/sites\/30\/2018\/07\/5-2.png\" alt=\"\" width=\"585\" height=\"58\" \/><\/p>\r\n<p style=\"text-align: justify;\">The below code snippet display numbers from 1 to 10 using while loop. In the example, we have used the variable 'i' as looping variable.<\/p>\r\n<p style=\"text-align: center;\"><img class=\"size-full wp-image-481 aligncenter\" src=\"http:\/\/itp7.epgpbooks.inflibnet.ac.in\/wp-content\/uploads\/sites\/30\/2018\/07\/6-2.png\" alt=\"\" width=\"635\" height=\"431\" \/><\/p>\r\n<p style=\"text-align: justify;\">The for loop iterates for definite number of values given in sequence. In the above example, we created a vector 'x' of values 1 to 8. In the above example, for loop iterated 8 times taking the assigned values one at a time. It must be noted that the for loop of R is different from that of C programming.<\/p>\r\n&nbsp;\r\n\r\n<strong>Break and Next keywords<\/strong>\r\n\r\n&nbsp;\r\n<p style=\"text-align: justify;\">The break and next keywords are used in R that are similar in other programming languages. The break keyword is used to come out of loop based on certain criteria while the next keyword is used to continue execution till the criteria is met. Let us see examples that demonstrate break and next keywords. In the below code, the loop must iterate for 15 times, however, when the loop encounter value of 13, it breaks out of the loop and terminates.<\/p>\r\n<p style=\"text-align: center;\"><img class=\"size-full wp-image-482 aligncenter\" src=\"http:\/\/itp7.epgpbooks.inflibnet.ac.in\/wp-content\/uploads\/sites\/30\/2018\/07\/7-2.png\" alt=\"\" width=\"585\" height=\"150\" \/><\/p>\r\n<p style=\"text-align: justify;\">In the following example, the loop iterates for 20 times, however, when the loop encounters the value of 13, it skips the value (does not print) and continues till the terminating criteria is satisfied.<\/p>\r\n<p style=\"text-align: center;\"><img class=\"size-full wp-image-483 aligncenter\" src=\"http:\/\/itp7.epgpbooks.inflibnet.ac.in\/wp-content\/uploads\/sites\/30\/2018\/07\/8-5.png\" alt=\"\" width=\"590\" height=\"183\" \/><\/p>\r\n<strong>Writing Interactive Programs<\/strong>\r\n\r\n&nbsp;\r\n<p style=\"text-align: justify;\">Now, let us see an interactive program where the input is given by a user. The following program checks whether a number entered by the user is prime or not. In the first line of the program, you may notice that we accept input using 'prompt()' function, the input is read using the 'readline()' function and later converted into integer using the'as.integer()' function.<\/p>\r\n&nbsp;\r\n<p style=\"text-align: justify;\">In the following program, the for loop is used differently. We have iterated the loop from value 2 upto the value 'num-1'. You may notice the syntax of for loop since it is bit different from the loop that we studied earlier in this module.<\/p>\r\n&nbsp;\r\n<p style=\"text-align: center;\"><img class=\"size-full wp-image-484 aligncenter\" src=\"http:\/\/itp7.epgpbooks.inflibnet.ac.in\/wp-content\/uploads\/sites\/30\/2018\/07\/9-3.png\" alt=\"\" width=\"585\" height=\"308\" \/><\/p>\r\n<p style=\"text-align: center;\"><img class=\"size-full wp-image-485 aligncenter\" src=\"http:\/\/itp7.epgpbooks.inflibnet.ac.in\/wp-content\/uploads\/sites\/30\/2018\/07\/10-3.png\" alt=\"\" width=\"578\" height=\"173\" \/><\/p>\r\n<strong>Reading data from files<\/strong>\r\n\r\n&nbsp;\r\n<p style=\"text-align: justify;\">Let us study how to ready data from CSV files. Suppose we have a file \"input.csv\" in the default working directory. We need to use the function \"read.csv()\" to read the data from CSV file. Further, we store the data into data frame. Each column of the data can be accessed by using '$' sign. For instance, the field with heading \"salary\" can be accessed by using the format (data$salary)<\/p>\r\n&nbsp;\r\n<p style=\"text-align: center;\"><img class=\"size-full wp-image-486 aligncenter\" src=\"http:\/\/itp7.epgpbooks.inflibnet.ac.in\/wp-content\/uploads\/sites\/30\/2018\/07\/11-3.png\" alt=\"\" width=\"585\" height=\"196\" \/><\/p>\r\n<strong>Plotting in R<\/strong>\r\n\r\n&nbsp;\r\n<p style=\"text-align: justify;\">R supports ploting features, such that data can be plotted from files or from data frames. R supports variety of plotting formats. The most prominent ones are as below:<\/p>\r\n\r\n<ul>\r\n \t<li>Box plots<\/li>\r\n \t<li>Scatter Plots<\/li>\r\n \t<li>Line Graphs<\/li>\r\n \t<li>Pie charts<\/li>\r\n \t<li>Bar charts<\/li>\r\n \t<li>Histograms<\/li>\r\n<\/ul>\r\nLet\u00a0 us see\u00a0 how plots can\u00a0 be created by issuing commands.\u00a0 By issuing the \"boxplot()\"function, R creates a box plot as shown in following figure:\r\n<p style=\"text-align: center;\"><img class=\"size-full wp-image-487 aligncenter\" src=\"http:\/\/itp7.epgpbooks.inflibnet.ac.in\/wp-content\/uploads\/sites\/30\/2018\/07\/12-2.png\" alt=\"\" width=\"640\" height=\"58\" \/><\/p>\r\n<p style=\"text-align: justify;\">In the above command, we are plotting data from \"mtcars\" dataset. The x-axis and y-axis are labelled accordingly. We have plotted the values of columns \"mpg\" and \"cyl\" .<\/p>\r\n&nbsp;\r\n<p style=\"text-align: center;\"><img class=\"size-full wp-image-488 aligncenter\" src=\"http:\/\/itp7.epgpbooks.inflibnet.ac.in\/wp-content\/uploads\/sites\/30\/2018\/07\/13.jpg\" alt=\"\" width=\"666\" height=\"665\" \/><\/p>\r\n<p style=\"text-align: center;\"><strong>Figure 2: Boxplot generated by R<\/strong><\/p>\r\n&nbsp;\r\n<p style=\"text-align: justify;\">Let us see one more example where we create a scatter plot using the \"mtcars\" dataset. In the following example, we create a scatter plot using the \"plot()\" function of R. We have also generated a file in png format and the output will be created as a png file.<\/p>\r\n&nbsp;\r\n<p style=\"text-align: center;\"><img class=\"size-full wp-image-489 aligncenter\" src=\"http:\/\/itp7.epgpbooks.inflibnet.ac.in\/wp-content\/uploads\/sites\/30\/2018\/07\/15-2.png\" alt=\"\" width=\"636\" height=\"454\" \/><\/p>\r\n<p style=\"text-align: center;\"><img class=\"size-full wp-image-490 aligncenter\" src=\"http:\/\/itp7.epgpbooks.inflibnet.ac.in\/wp-content\/uploads\/sites\/30\/2018\/07\/16.jpg\" alt=\"\" width=\"480\" height=\"480\" \/><\/p>\r\n<p style=\"text-align: center;\">Figure 3: Scatter plot of Weight Vs. Milage<\/p>\r\n&nbsp;\r\n\r\n<strong>Functions in R<\/strong>\r\n\r\n&nbsp;\r\n<p style=\"text-align: justify;\">R supports creation of user-defined functions. The R functions can take arguments and return the arguments. A function is created using \"function()\" keyword. Syntax of creating function is as shown below:<\/p>\r\n<p style=\"text-align: center;\"><img class=\"size-full wp-image-491 aligncenter\" src=\"http:\/\/itp7.epgpbooks.inflibnet.ac.in\/wp-content\/uploads\/sites\/30\/2018\/07\/17-1.png\" alt=\"\" width=\"629\" height=\"93\" \/><\/p>\r\n<p style=\"text-align: justify;\">Let us study an example where we create a function to print the square of numbers for a sequence of values. Let us create a user-defined function, \"myfunction()\" which calculates the square of values. In the following code snippet, you can see that we are creating a body of function. The bottom line issues a function call by specifying the function name and arguments passed onto that function.<\/p>\r\n<p style=\"text-align: center;\"><img class=\"size-full wp-image-492 aligncenter\" src=\"http:\/\/itp7.epgpbooks.inflibnet.ac.in\/wp-content\/uploads\/sites\/30\/2018\/07\/18.png\" alt=\"\" width=\"641\" height=\"70\" \/><\/p>\r\n<p style=\"text-align: center;\"><img class=\"size-full wp-image-493 aligncenter\" src=\"http:\/\/itp7.epgpbooks.inflibnet.ac.in\/wp-content\/uploads\/sites\/30\/2018\/07\/19.png\" alt=\"\" width=\"641\" height=\"198\" \/><\/p>\r\n&nbsp;\r\n<p style=\"text-align: justify;\">Let us study one more example where we have created a \"check()\" function. This function is used to check whether we have passed a positive value, negative value or zero as an argument. The below code demonstrates the use of \"check()\" function<\/p>\r\n<p style=\"text-align: center;\"><img class=\"size-full wp-image-494 aligncenter\" src=\"http:\/\/itp7.epgpbooks.inflibnet.ac.in\/wp-content\/uploads\/sites\/30\/2018\/07\/19-1.png\" alt=\"\" width=\"639\" height=\"275\" \/><\/p>\r\nLet us summarize the key concepts covered in this module\r\n<ul>\r\n \t<li>Simple Programming in R<\/li>\r\n \t<li>Using Loops and Decision statements<\/li>\r\n \t<li>Using Graphics<\/li>\r\n \t<li>Creating User Defined Functions<\/li>\r\n<\/ul>\r\n<table>\r\n<tbody>\r\n<tr>\r\n<td><strong>you can view video on R Programming - 2<\/strong><\/td>\r\n<td><a href=\"https:\/\/youtu.be\/r9PcMwmVkFo\" target=\"_blank\" rel=\"noopener\"><img class=\"alignnone wp-image-120\" src=\"http:\/\/epgpbooks.inflibnet.ac.in\/wp-content\/uploads\/2018\/11\/download.png\" alt=\"\" width=\"36\" height=\"36\" \/><\/a><\/td>\r\n<\/tr>\r\n<\/tbody>\r\n<\/table>\r\n\r\n<strong>References for R Programming:<\/strong>\r\n<ol>\r\n \t<li style=\"text-align: justify;\">Felix Alvaro. <em>R\u202f: Easy R programming for beginners, your step-by-step guide to<\/em> <em>learning R programming<\/em>,<\/li>\r\n \t<li style=\"text-align: justify;\">John Braun and Duncan James Murdoch. <em>A first course in statistical programming<\/em> <em>with R<\/em>,<\/li>\r\n \t<li style=\"text-align: justify;\">John M. Chambers. 2008. <em>Software for data analysis\u202f: programming with R<\/em>, Springer.<\/li>\r\n \t<li style=\"text-align: justify;\">Michael J. Crawley. <em>The R book<\/em>,<\/li>\r\n \t<li style=\"text-align: justify;\">Tilman M. Davies. <em>The book of R\u202f: a first course in programming and statistics<\/em>,<\/li>\r\n \t<li style=\"text-align: justify;\">Mark. Gardener. 2012. <em>Beginning R\u202f: the Statistical Programming Language.<\/em>, John Wiley &amp; Sons.<\/li>\r\n \t<li style=\"text-align: justify;\">Colin (Colin Stevenson) Gillespie and Robin Lovelace. <em>Efficient R programming\u202f: a<\/em> <em>practical guide to smarter programming<\/em>,<\/li>\r\n \t<li style=\"text-align: justify;\">Garrett Grolemund. <em>Hands-on programming with R<\/em>,<\/li>\r\n \t<li style=\"text-align: justify;\">Thomas Mailund. <em>Advanced Object-Oriented Programming in R\u202f: Statistical\u00a0<\/em><em style=\"text-align: initial; font-size: 1em;\">Programming for Data Science, Analysis and Finance<\/em><span style=\"text-align: initial; font-size: 1em;\">,<\/span><\/li>\r\n \t<li style=\"text-align: justify;\">Norman S. Matloff. 2011. <em>The art of R programming\u202f: tour of statistical software<\/em> <em>design<\/em>, No Starch Press.<\/li>\r\n \t<li style=\"text-align: justify;\">Shuichi Ohsaki, Jori Ruppert-Felsot, and Daisuke Yoshikawa. <em>R programming and its<\/em> <em>applications in financial mathematics<\/em>,<\/li>\r\n \t<li style=\"text-align: justify;\">Kun Ren. <em>Modern R programming cookbook\u202f: recipes to simplify your statistical<\/em> <em>applications<\/em>,<\/li>\r\n \t<li style=\"text-align: justify;\">Kun Ren. <em>Learning R programming\u202f: become an efficient data scientist with R<\/em>,<\/li>\r\n \t<li style=\"text-align: justify;\">Omar. Trejo and Peter. C. Figliozzi. 2017. <em>R Programming By Example Practical,<\/em> <em>hands-on projects to help you get started with R.<\/em>, Packt Publishing.<\/li>\r\n \t<li style=\"text-align: justify;\">Alain F. Zuur, Elena N. Ieno, and Erik. Meesters. 2009. <em>A beginner\u2019s guide to R<\/em>, Springer.<\/li>\r\n \t<li style=\"text-align: justify;\">Anon. R: The R Project for Statistical Computing. Retrieved March 19, 2017 from https:\/\/www.r-project.org\/<\/li>\r\n<\/ol>","rendered":"<div><span style=\"float: right;\"><a href=\"https:\/\/youtu.be\/r9PcMwmVkFo\" target=\"_blank\" rel=\"noopener\"><img decoding=\"async\" src=\"http:\/\/epgpbooks.inflibnet.ac.in\/wp-content\/uploads\/2018\/11\/download.png\" alt=\"epgp books\" width=\"75px\" height=\"75px;\" \/><\/a><br \/>\n<\/span><\/div>\n<p>&nbsp;<\/p>\n<p><strong>Writing Scripts<\/strong><\/p>\n<p>&nbsp;<\/p>\n<p style=\"text-align: justify;\">In the previous module of R programming &#8211; 1, we had studied the capabilities provide by R Environment. We had seen the use of variables, operators, data structures and datasets in R. In this module, we will study how to write programs in R. This module will cover the basic programming constructs provided by R environment. Let us begin our study by typing a simple program that performs addition calculation. The following code performs addition of subject marks of 3 different subjects. Further, it calculates the percentage and is displayed on screen.<\/p>\n<p>&nbsp;<\/p>\n<p style=\"text-align: center;\"><img loading=\"lazy\" decoding=\"async\" class=\"size-full wp-image-476 aligncenter\" src=\"http:\/\/itp7.epgpbooks.inflibnet.ac.in\/wp-content\/uploads\/sites\/30\/2018\/07\/1-4.png\" alt=\"\" width=\"584\" height=\"157\" srcset=\"https:\/\/ebooks.inflibnet.ac.in\/itp7\/wp-content\/uploads\/sites\/30\/2018\/07\/1-4.png 584w, https:\/\/ebooks.inflibnet.ac.in\/itp7\/wp-content\/uploads\/sites\/30\/2018\/07\/1-4-300x81.png 300w, https:\/\/ebooks.inflibnet.ac.in\/itp7\/wp-content\/uploads\/sites\/30\/2018\/07\/1-4-65x17.png 65w, https:\/\/ebooks.inflibnet.ac.in\/itp7\/wp-content\/uploads\/sites\/30\/2018\/07\/1-4-225x60.png 225w, https:\/\/ebooks.inflibnet.ac.in\/itp7\/wp-content\/uploads\/sites\/30\/2018\/07\/1-4-350x94.png 350w\" sizes=\"auto, (max-width: 584px) 100vw, 584px\" \/><\/p>\n<p style=\"text-align: justify;\">Rather than typing the program in a text editor and executing it from command prompt, we can use GUI to make the tasks easier. RStudio is a free GUI available for R programming. The following is a screen shot of RStudio:<\/p>\n<p style=\"text-align: center;\"><img loading=\"lazy\" decoding=\"async\" class=\"size-full wp-image-477 aligncenter\" src=\"http:\/\/itp7.epgpbooks.inflibnet.ac.in\/wp-content\/uploads\/sites\/30\/2018\/07\/2-3.jpg\" alt=\"\" width=\"1366\" height=\"730\" srcset=\"https:\/\/ebooks.inflibnet.ac.in\/itp7\/wp-content\/uploads\/sites\/30\/2018\/07\/2-3.jpg 1366w, https:\/\/ebooks.inflibnet.ac.in\/itp7\/wp-content\/uploads\/sites\/30\/2018\/07\/2-3-300x160.jpg 300w, https:\/\/ebooks.inflibnet.ac.in\/itp7\/wp-content\/uploads\/sites\/30\/2018\/07\/2-3-768x410.jpg 768w, https:\/\/ebooks.inflibnet.ac.in\/itp7\/wp-content\/uploads\/sites\/30\/2018\/07\/2-3-1024x547.jpg 1024w, https:\/\/ebooks.inflibnet.ac.in\/itp7\/wp-content\/uploads\/sites\/30\/2018\/07\/2-3-65x35.jpg 65w, https:\/\/ebooks.inflibnet.ac.in\/itp7\/wp-content\/uploads\/sites\/30\/2018\/07\/2-3-225x120.jpg 225w, https:\/\/ebooks.inflibnet.ac.in\/itp7\/wp-content\/uploads\/sites\/30\/2018\/07\/2-3-350x187.jpg 350w\" sizes=\"auto, (max-width: 1366px) 100vw, 1366px\" \/><\/p>\n<p style=\"text-align: center;\">Figure 1: Rstudio &#8211; GUI for R programming<\/p>\n<p>&nbsp;<\/p>\n<p style=\"text-align: justify;\">As you can see in the GUI, there are 4 panels, there is an editor to type the programs, the output of which is seen in console at the bottom of editor. There is also a watch windows to observe the values of variables while the programming is running. The panel provided in bottom right corner lists files of the directory, packages installed in R, it can also be used to view plots or to browse help.<\/p>\n<p>&nbsp;<\/p>\n<p><strong>Decision Making<\/strong><\/p>\n<p>&nbsp;<\/p>\n<p style=\"text-align: justify;\">As in other programming languages, R supports decision making facilities like if statements.<\/p>\n<p>The syntax of if statement is as below:<\/p>\n<p style=\"text-align: center;\"><img loading=\"lazy\" decoding=\"async\" class=\"size-full wp-image-478 aligncenter\" src=\"http:\/\/itp7.epgpbooks.inflibnet.ac.in\/wp-content\/uploads\/sites\/30\/2018\/07\/3-3.png\" alt=\"\" width=\"581\" height=\"153\" srcset=\"https:\/\/ebooks.inflibnet.ac.in\/itp7\/wp-content\/uploads\/sites\/30\/2018\/07\/3-3.png 581w, https:\/\/ebooks.inflibnet.ac.in\/itp7\/wp-content\/uploads\/sites\/30\/2018\/07\/3-3-300x79.png 300w, https:\/\/ebooks.inflibnet.ac.in\/itp7\/wp-content\/uploads\/sites\/30\/2018\/07\/3-3-65x17.png 65w, https:\/\/ebooks.inflibnet.ac.in\/itp7\/wp-content\/uploads\/sites\/30\/2018\/07\/3-3-225x59.png 225w, https:\/\/ebooks.inflibnet.ac.in\/itp7\/wp-content\/uploads\/sites\/30\/2018\/07\/3-3-350x92.png 350w\" sizes=\"auto, (max-width: 581px) 100vw, 581px\" \/><\/p>\n<p style=\"text-align: justify;\">We must be careful while using if statement, since the closing parenthesis &#8216;}&#8217; and else keyword must be in the same line. Let us see a sample program that uses decision making. The following example checks whether a number is negative or positive number and display accordingly:<\/p>\n<p style=\"text-align: center;\"><img loading=\"lazy\" decoding=\"async\" class=\"size-full wp-image-479 aligncenter\" src=\"http:\/\/itp7.epgpbooks.inflibnet.ac.in\/wp-content\/uploads\/sites\/30\/2018\/07\/4-3.png\" alt=\"\" width=\"578\" height=\"112\" srcset=\"https:\/\/ebooks.inflibnet.ac.in\/itp7\/wp-content\/uploads\/sites\/30\/2018\/07\/4-3.png 578w, https:\/\/ebooks.inflibnet.ac.in\/itp7\/wp-content\/uploads\/sites\/30\/2018\/07\/4-3-300x58.png 300w, https:\/\/ebooks.inflibnet.ac.in\/itp7\/wp-content\/uploads\/sites\/30\/2018\/07\/4-3-65x13.png 65w, https:\/\/ebooks.inflibnet.ac.in\/itp7\/wp-content\/uploads\/sites\/30\/2018\/07\/4-3-225x44.png 225w, https:\/\/ebooks.inflibnet.ac.in\/itp7\/wp-content\/uploads\/sites\/30\/2018\/07\/4-3-350x68.png 350w\" sizes=\"auto, (max-width: 578px) 100vw, 578px\" \/><\/p>\n<p><strong>Looping in R<\/strong><\/p>\n<p>&nbsp;<\/p>\n<p style=\"text-align: justify;\">R supports looping construct in the form of while loop and for loops. The syntax of while loop is as shown below:<\/p>\n<p style=\"text-align: center;\"><img loading=\"lazy\" decoding=\"async\" class=\"size-full wp-image-480 aligncenter\" src=\"http:\/\/itp7.epgpbooks.inflibnet.ac.in\/wp-content\/uploads\/sites\/30\/2018\/07\/5-2.png\" alt=\"\" width=\"585\" height=\"58\" srcset=\"https:\/\/ebooks.inflibnet.ac.in\/itp7\/wp-content\/uploads\/sites\/30\/2018\/07\/5-2.png 585w, https:\/\/ebooks.inflibnet.ac.in\/itp7\/wp-content\/uploads\/sites\/30\/2018\/07\/5-2-300x30.png 300w, https:\/\/ebooks.inflibnet.ac.in\/itp7\/wp-content\/uploads\/sites\/30\/2018\/07\/5-2-65x6.png 65w, https:\/\/ebooks.inflibnet.ac.in\/itp7\/wp-content\/uploads\/sites\/30\/2018\/07\/5-2-225x22.png 225w, https:\/\/ebooks.inflibnet.ac.in\/itp7\/wp-content\/uploads\/sites\/30\/2018\/07\/5-2-350x35.png 350w\" sizes=\"auto, (max-width: 585px) 100vw, 585px\" \/><\/p>\n<p style=\"text-align: justify;\">The below code snippet display numbers from 1 to 10 using while loop. In the example, we have used the variable &#8216;i&#8217; as looping variable.<\/p>\n<p style=\"text-align: center;\"><img loading=\"lazy\" decoding=\"async\" class=\"size-full wp-image-481 aligncenter\" src=\"http:\/\/itp7.epgpbooks.inflibnet.ac.in\/wp-content\/uploads\/sites\/30\/2018\/07\/6-2.png\" alt=\"\" width=\"635\" height=\"431\" srcset=\"https:\/\/ebooks.inflibnet.ac.in\/itp7\/wp-content\/uploads\/sites\/30\/2018\/07\/6-2.png 635w, https:\/\/ebooks.inflibnet.ac.in\/itp7\/wp-content\/uploads\/sites\/30\/2018\/07\/6-2-300x204.png 300w, https:\/\/ebooks.inflibnet.ac.in\/itp7\/wp-content\/uploads\/sites\/30\/2018\/07\/6-2-65x44.png 65w, https:\/\/ebooks.inflibnet.ac.in\/itp7\/wp-content\/uploads\/sites\/30\/2018\/07\/6-2-225x153.png 225w, https:\/\/ebooks.inflibnet.ac.in\/itp7\/wp-content\/uploads\/sites\/30\/2018\/07\/6-2-350x238.png 350w\" sizes=\"auto, (max-width: 635px) 100vw, 635px\" \/><\/p>\n<p style=\"text-align: justify;\">The for loop iterates for definite number of values given in sequence. In the above example, we created a vector &#8216;x&#8217; of values 1 to 8. In the above example, for loop iterated 8 times taking the assigned values one at a time. It must be noted that the for loop of R is different from that of C programming.<\/p>\n<p>&nbsp;<\/p>\n<p><strong>Break and Next keywords<\/strong><\/p>\n<p>&nbsp;<\/p>\n<p style=\"text-align: justify;\">The break and next keywords are used in R that are similar in other programming languages. The break keyword is used to come out of loop based on certain criteria while the next keyword is used to continue execution till the criteria is met. Let us see examples that demonstrate break and next keywords. In the below code, the loop must iterate for 15 times, however, when the loop encounter value of 13, it breaks out of the loop and terminates.<\/p>\n<p style=\"text-align: center;\"><img loading=\"lazy\" decoding=\"async\" class=\"size-full wp-image-482 aligncenter\" src=\"http:\/\/itp7.epgpbooks.inflibnet.ac.in\/wp-content\/uploads\/sites\/30\/2018\/07\/7-2.png\" alt=\"\" width=\"585\" height=\"150\" srcset=\"https:\/\/ebooks.inflibnet.ac.in\/itp7\/wp-content\/uploads\/sites\/30\/2018\/07\/7-2.png 585w, https:\/\/ebooks.inflibnet.ac.in\/itp7\/wp-content\/uploads\/sites\/30\/2018\/07\/7-2-300x77.png 300w, https:\/\/ebooks.inflibnet.ac.in\/itp7\/wp-content\/uploads\/sites\/30\/2018\/07\/7-2-65x17.png 65w, https:\/\/ebooks.inflibnet.ac.in\/itp7\/wp-content\/uploads\/sites\/30\/2018\/07\/7-2-225x58.png 225w, https:\/\/ebooks.inflibnet.ac.in\/itp7\/wp-content\/uploads\/sites\/30\/2018\/07\/7-2-350x90.png 350w\" sizes=\"auto, (max-width: 585px) 100vw, 585px\" \/><\/p>\n<p style=\"text-align: justify;\">In the following example, the loop iterates for 20 times, however, when the loop encounters the value of 13, it skips the value (does not print) and continues till the terminating criteria is satisfied.<\/p>\n<p style=\"text-align: center;\"><img loading=\"lazy\" decoding=\"async\" class=\"size-full wp-image-483 aligncenter\" src=\"http:\/\/itp7.epgpbooks.inflibnet.ac.in\/wp-content\/uploads\/sites\/30\/2018\/07\/8-5.png\" alt=\"\" width=\"590\" height=\"183\" srcset=\"https:\/\/ebooks.inflibnet.ac.in\/itp7\/wp-content\/uploads\/sites\/30\/2018\/07\/8-5.png 590w, https:\/\/ebooks.inflibnet.ac.in\/itp7\/wp-content\/uploads\/sites\/30\/2018\/07\/8-5-300x93.png 300w, https:\/\/ebooks.inflibnet.ac.in\/itp7\/wp-content\/uploads\/sites\/30\/2018\/07\/8-5-65x20.png 65w, https:\/\/ebooks.inflibnet.ac.in\/itp7\/wp-content\/uploads\/sites\/30\/2018\/07\/8-5-225x70.png 225w, https:\/\/ebooks.inflibnet.ac.in\/itp7\/wp-content\/uploads\/sites\/30\/2018\/07\/8-5-350x109.png 350w\" sizes=\"auto, (max-width: 590px) 100vw, 590px\" \/><\/p>\n<p><strong>Writing Interactive Programs<\/strong><\/p>\n<p>&nbsp;<\/p>\n<p style=\"text-align: justify;\">Now, let us see an interactive program where the input is given by a user. The following program checks whether a number entered by the user is prime or not. In the first line of the program, you may notice that we accept input using &#8216;prompt()&#8217; function, the input is read using the &#8216;readline()&#8217; function and later converted into integer using the&#8217;as.integer()&#8217; function.<\/p>\n<p>&nbsp;<\/p>\n<p style=\"text-align: justify;\">In the following program, the for loop is used differently. We have iterated the loop from value 2 upto the value &#8216;num-1&#8217;. You may notice the syntax of for loop since it is bit different from the loop that we studied earlier in this module.<\/p>\n<p>&nbsp;<\/p>\n<p style=\"text-align: center;\"><img loading=\"lazy\" decoding=\"async\" class=\"size-full wp-image-484 aligncenter\" src=\"http:\/\/itp7.epgpbooks.inflibnet.ac.in\/wp-content\/uploads\/sites\/30\/2018\/07\/9-3.png\" alt=\"\" width=\"585\" height=\"308\" srcset=\"https:\/\/ebooks.inflibnet.ac.in\/itp7\/wp-content\/uploads\/sites\/30\/2018\/07\/9-3.png 585w, https:\/\/ebooks.inflibnet.ac.in\/itp7\/wp-content\/uploads\/sites\/30\/2018\/07\/9-3-300x158.png 300w, https:\/\/ebooks.inflibnet.ac.in\/itp7\/wp-content\/uploads\/sites\/30\/2018\/07\/9-3-65x34.png 65w, https:\/\/ebooks.inflibnet.ac.in\/itp7\/wp-content\/uploads\/sites\/30\/2018\/07\/9-3-225x118.png 225w, https:\/\/ebooks.inflibnet.ac.in\/itp7\/wp-content\/uploads\/sites\/30\/2018\/07\/9-3-350x184.png 350w\" sizes=\"auto, (max-width: 585px) 100vw, 585px\" \/><\/p>\n<p style=\"text-align: center;\"><img loading=\"lazy\" decoding=\"async\" class=\"size-full wp-image-485 aligncenter\" src=\"http:\/\/itp7.epgpbooks.inflibnet.ac.in\/wp-content\/uploads\/sites\/30\/2018\/07\/10-3.png\" alt=\"\" width=\"578\" height=\"173\" srcset=\"https:\/\/ebooks.inflibnet.ac.in\/itp7\/wp-content\/uploads\/sites\/30\/2018\/07\/10-3.png 578w, https:\/\/ebooks.inflibnet.ac.in\/itp7\/wp-content\/uploads\/sites\/30\/2018\/07\/10-3-300x90.png 300w, https:\/\/ebooks.inflibnet.ac.in\/itp7\/wp-content\/uploads\/sites\/30\/2018\/07\/10-3-65x19.png 65w, https:\/\/ebooks.inflibnet.ac.in\/itp7\/wp-content\/uploads\/sites\/30\/2018\/07\/10-3-225x67.png 225w, https:\/\/ebooks.inflibnet.ac.in\/itp7\/wp-content\/uploads\/sites\/30\/2018\/07\/10-3-350x105.png 350w\" sizes=\"auto, (max-width: 578px) 100vw, 578px\" \/><\/p>\n<p><strong>Reading data from files<\/strong><\/p>\n<p>&nbsp;<\/p>\n<p style=\"text-align: justify;\">Let us study how to ready data from CSV files. Suppose we have a file &#8220;input.csv&#8221; in the default working directory. We need to use the function &#8220;read.csv()&#8221; to read the data from CSV file. Further, we store the data into data frame. Each column of the data can be accessed by using &#8216;$&#8217; sign. For instance, the field with heading &#8220;salary&#8221; can be accessed by using the format (data$salary)<\/p>\n<p>&nbsp;<\/p>\n<p style=\"text-align: center;\"><img loading=\"lazy\" decoding=\"async\" class=\"size-full wp-image-486 aligncenter\" src=\"http:\/\/itp7.epgpbooks.inflibnet.ac.in\/wp-content\/uploads\/sites\/30\/2018\/07\/11-3.png\" alt=\"\" width=\"585\" height=\"196\" srcset=\"https:\/\/ebooks.inflibnet.ac.in\/itp7\/wp-content\/uploads\/sites\/30\/2018\/07\/11-3.png 585w, https:\/\/ebooks.inflibnet.ac.in\/itp7\/wp-content\/uploads\/sites\/30\/2018\/07\/11-3-300x101.png 300w, https:\/\/ebooks.inflibnet.ac.in\/itp7\/wp-content\/uploads\/sites\/30\/2018\/07\/11-3-65x22.png 65w, https:\/\/ebooks.inflibnet.ac.in\/itp7\/wp-content\/uploads\/sites\/30\/2018\/07\/11-3-225x75.png 225w, https:\/\/ebooks.inflibnet.ac.in\/itp7\/wp-content\/uploads\/sites\/30\/2018\/07\/11-3-350x117.png 350w\" sizes=\"auto, (max-width: 585px) 100vw, 585px\" \/><\/p>\n<p><strong>Plotting in R<\/strong><\/p>\n<p>&nbsp;<\/p>\n<p style=\"text-align: justify;\">R supports ploting features, such that data can be plotted from files or from data frames. R supports variety of plotting formats. The most prominent ones are as below:<\/p>\n<ul>\n<li>Box plots<\/li>\n<li>Scatter Plots<\/li>\n<li>Line Graphs<\/li>\n<li>Pie charts<\/li>\n<li>Bar charts<\/li>\n<li>Histograms<\/li>\n<\/ul>\n<p>Let\u00a0 us see\u00a0 how plots can\u00a0 be created by issuing commands.\u00a0 By issuing the &#8220;boxplot()&#8221;function, R creates a box plot as shown in following figure:<\/p>\n<p style=\"text-align: center;\"><img loading=\"lazy\" decoding=\"async\" class=\"size-full wp-image-487 aligncenter\" src=\"http:\/\/itp7.epgpbooks.inflibnet.ac.in\/wp-content\/uploads\/sites\/30\/2018\/07\/12-2.png\" alt=\"\" width=\"640\" height=\"58\" srcset=\"https:\/\/ebooks.inflibnet.ac.in\/itp7\/wp-content\/uploads\/sites\/30\/2018\/07\/12-2.png 640w, https:\/\/ebooks.inflibnet.ac.in\/itp7\/wp-content\/uploads\/sites\/30\/2018\/07\/12-2-300x27.png 300w, https:\/\/ebooks.inflibnet.ac.in\/itp7\/wp-content\/uploads\/sites\/30\/2018\/07\/12-2-65x6.png 65w, https:\/\/ebooks.inflibnet.ac.in\/itp7\/wp-content\/uploads\/sites\/30\/2018\/07\/12-2-225x20.png 225w, https:\/\/ebooks.inflibnet.ac.in\/itp7\/wp-content\/uploads\/sites\/30\/2018\/07\/12-2-350x32.png 350w\" sizes=\"auto, (max-width: 640px) 100vw, 640px\" \/><\/p>\n<p style=\"text-align: justify;\">In the above command, we are plotting data from &#8220;mtcars&#8221; dataset. The x-axis and y-axis are labelled accordingly. We have plotted the values of columns &#8220;mpg&#8221; and &#8220;cyl&#8221; .<\/p>\n<p>&nbsp;<\/p>\n<p style=\"text-align: center;\"><img loading=\"lazy\" decoding=\"async\" class=\"size-full wp-image-488 aligncenter\" src=\"http:\/\/itp7.epgpbooks.inflibnet.ac.in\/wp-content\/uploads\/sites\/30\/2018\/07\/13.jpg\" alt=\"\" width=\"666\" height=\"665\" srcset=\"https:\/\/ebooks.inflibnet.ac.in\/itp7\/wp-content\/uploads\/sites\/30\/2018\/07\/13.jpg 666w, https:\/\/ebooks.inflibnet.ac.in\/itp7\/wp-content\/uploads\/sites\/30\/2018\/07\/13-150x150.jpg 150w, https:\/\/ebooks.inflibnet.ac.in\/itp7\/wp-content\/uploads\/sites\/30\/2018\/07\/13-300x300.jpg 300w, https:\/\/ebooks.inflibnet.ac.in\/itp7\/wp-content\/uploads\/sites\/30\/2018\/07\/13-65x65.jpg 65w, https:\/\/ebooks.inflibnet.ac.in\/itp7\/wp-content\/uploads\/sites\/30\/2018\/07\/13-225x225.jpg 225w, https:\/\/ebooks.inflibnet.ac.in\/itp7\/wp-content\/uploads\/sites\/30\/2018\/07\/13-350x349.jpg 350w\" sizes=\"auto, (max-width: 666px) 100vw, 666px\" \/><\/p>\n<p style=\"text-align: center;\"><strong>Figure 2: Boxplot generated by R<\/strong><\/p>\n<p>&nbsp;<\/p>\n<p style=\"text-align: justify;\">Let us see one more example where we create a scatter plot using the &#8220;mtcars&#8221; dataset. In the following example, we create a scatter plot using the &#8220;plot()&#8221; function of R. We have also generated a file in png format and the output will be created as a png file.<\/p>\n<p>&nbsp;<\/p>\n<p style=\"text-align: center;\"><img loading=\"lazy\" decoding=\"async\" class=\"size-full wp-image-489 aligncenter\" src=\"http:\/\/itp7.epgpbooks.inflibnet.ac.in\/wp-content\/uploads\/sites\/30\/2018\/07\/15-2.png\" alt=\"\" width=\"636\" height=\"454\" srcset=\"https:\/\/ebooks.inflibnet.ac.in\/itp7\/wp-content\/uploads\/sites\/30\/2018\/07\/15-2.png 636w, https:\/\/ebooks.inflibnet.ac.in\/itp7\/wp-content\/uploads\/sites\/30\/2018\/07\/15-2-300x214.png 300w, https:\/\/ebooks.inflibnet.ac.in\/itp7\/wp-content\/uploads\/sites\/30\/2018\/07\/15-2-65x46.png 65w, https:\/\/ebooks.inflibnet.ac.in\/itp7\/wp-content\/uploads\/sites\/30\/2018\/07\/15-2-225x161.png 225w, https:\/\/ebooks.inflibnet.ac.in\/itp7\/wp-content\/uploads\/sites\/30\/2018\/07\/15-2-350x250.png 350w\" sizes=\"auto, (max-width: 636px) 100vw, 636px\" \/><\/p>\n<p style=\"text-align: center;\"><img loading=\"lazy\" decoding=\"async\" class=\"size-full wp-image-490 aligncenter\" src=\"http:\/\/itp7.epgpbooks.inflibnet.ac.in\/wp-content\/uploads\/sites\/30\/2018\/07\/16.jpg\" alt=\"\" width=\"480\" height=\"480\" srcset=\"https:\/\/ebooks.inflibnet.ac.in\/itp7\/wp-content\/uploads\/sites\/30\/2018\/07\/16.jpg 480w, https:\/\/ebooks.inflibnet.ac.in\/itp7\/wp-content\/uploads\/sites\/30\/2018\/07\/16-150x150.jpg 150w, https:\/\/ebooks.inflibnet.ac.in\/itp7\/wp-content\/uploads\/sites\/30\/2018\/07\/16-300x300.jpg 300w, https:\/\/ebooks.inflibnet.ac.in\/itp7\/wp-content\/uploads\/sites\/30\/2018\/07\/16-65x65.jpg 65w, https:\/\/ebooks.inflibnet.ac.in\/itp7\/wp-content\/uploads\/sites\/30\/2018\/07\/16-225x225.jpg 225w, https:\/\/ebooks.inflibnet.ac.in\/itp7\/wp-content\/uploads\/sites\/30\/2018\/07\/16-350x350.jpg 350w\" sizes=\"auto, (max-width: 480px) 100vw, 480px\" \/><\/p>\n<p style=\"text-align: center;\">Figure 3: Scatter plot of Weight Vs. Milage<\/p>\n<p>&nbsp;<\/p>\n<p><strong>Functions in R<\/strong><\/p>\n<p>&nbsp;<\/p>\n<p style=\"text-align: justify;\">R supports creation of user-defined functions. The R functions can take arguments and return the arguments. A function is created using &#8220;function()&#8221; keyword. Syntax of creating function is as shown below:<\/p>\n<p style=\"text-align: center;\"><img loading=\"lazy\" decoding=\"async\" class=\"size-full wp-image-491 aligncenter\" src=\"http:\/\/itp7.epgpbooks.inflibnet.ac.in\/wp-content\/uploads\/sites\/30\/2018\/07\/17-1.png\" alt=\"\" width=\"629\" height=\"93\" srcset=\"https:\/\/ebooks.inflibnet.ac.in\/itp7\/wp-content\/uploads\/sites\/30\/2018\/07\/17-1.png 629w, https:\/\/ebooks.inflibnet.ac.in\/itp7\/wp-content\/uploads\/sites\/30\/2018\/07\/17-1-300x44.png 300w, https:\/\/ebooks.inflibnet.ac.in\/itp7\/wp-content\/uploads\/sites\/30\/2018\/07\/17-1-65x10.png 65w, https:\/\/ebooks.inflibnet.ac.in\/itp7\/wp-content\/uploads\/sites\/30\/2018\/07\/17-1-225x33.png 225w, https:\/\/ebooks.inflibnet.ac.in\/itp7\/wp-content\/uploads\/sites\/30\/2018\/07\/17-1-350x52.png 350w\" sizes=\"auto, (max-width: 629px) 100vw, 629px\" \/><\/p>\n<p style=\"text-align: justify;\">Let us study an example where we create a function to print the square of numbers for a sequence of values. Let us create a user-defined function, &#8220;myfunction()&#8221; which calculates the square of values. In the following code snippet, you can see that we are creating a body of function. The bottom line issues a function call by specifying the function name and arguments passed onto that function.<\/p>\n<p style=\"text-align: center;\"><img loading=\"lazy\" decoding=\"async\" class=\"size-full wp-image-492 aligncenter\" src=\"http:\/\/itp7.epgpbooks.inflibnet.ac.in\/wp-content\/uploads\/sites\/30\/2018\/07\/18.png\" alt=\"\" width=\"641\" height=\"70\" srcset=\"https:\/\/ebooks.inflibnet.ac.in\/itp7\/wp-content\/uploads\/sites\/30\/2018\/07\/18.png 641w, https:\/\/ebooks.inflibnet.ac.in\/itp7\/wp-content\/uploads\/sites\/30\/2018\/07\/18-300x33.png 300w, https:\/\/ebooks.inflibnet.ac.in\/itp7\/wp-content\/uploads\/sites\/30\/2018\/07\/18-65x7.png 65w, https:\/\/ebooks.inflibnet.ac.in\/itp7\/wp-content\/uploads\/sites\/30\/2018\/07\/18-225x25.png 225w, https:\/\/ebooks.inflibnet.ac.in\/itp7\/wp-content\/uploads\/sites\/30\/2018\/07\/18-350x38.png 350w\" sizes=\"auto, (max-width: 641px) 100vw, 641px\" \/><\/p>\n<p style=\"text-align: center;\"><img loading=\"lazy\" decoding=\"async\" class=\"size-full wp-image-493 aligncenter\" src=\"http:\/\/itp7.epgpbooks.inflibnet.ac.in\/wp-content\/uploads\/sites\/30\/2018\/07\/19.png\" alt=\"\" width=\"641\" height=\"198\" srcset=\"https:\/\/ebooks.inflibnet.ac.in\/itp7\/wp-content\/uploads\/sites\/30\/2018\/07\/19.png 641w, https:\/\/ebooks.inflibnet.ac.in\/itp7\/wp-content\/uploads\/sites\/30\/2018\/07\/19-300x93.png 300w, https:\/\/ebooks.inflibnet.ac.in\/itp7\/wp-content\/uploads\/sites\/30\/2018\/07\/19-65x20.png 65w, https:\/\/ebooks.inflibnet.ac.in\/itp7\/wp-content\/uploads\/sites\/30\/2018\/07\/19-225x70.png 225w, https:\/\/ebooks.inflibnet.ac.in\/itp7\/wp-content\/uploads\/sites\/30\/2018\/07\/19-350x108.png 350w\" sizes=\"auto, (max-width: 641px) 100vw, 641px\" \/><\/p>\n<p>&nbsp;<\/p>\n<p style=\"text-align: justify;\">Let us study one more example where we have created a &#8220;check()&#8221; function. This function is used to check whether we have passed a positive value, negative value or zero as an argument. The below code demonstrates the use of &#8220;check()&#8221; function<\/p>\n<p style=\"text-align: center;\"><img loading=\"lazy\" decoding=\"async\" class=\"size-full wp-image-494 aligncenter\" src=\"http:\/\/itp7.epgpbooks.inflibnet.ac.in\/wp-content\/uploads\/sites\/30\/2018\/07\/19-1.png\" alt=\"\" width=\"639\" height=\"275\" srcset=\"https:\/\/ebooks.inflibnet.ac.in\/itp7\/wp-content\/uploads\/sites\/30\/2018\/07\/19-1.png 639w, https:\/\/ebooks.inflibnet.ac.in\/itp7\/wp-content\/uploads\/sites\/30\/2018\/07\/19-1-300x129.png 300w, https:\/\/ebooks.inflibnet.ac.in\/itp7\/wp-content\/uploads\/sites\/30\/2018\/07\/19-1-65x28.png 65w, https:\/\/ebooks.inflibnet.ac.in\/itp7\/wp-content\/uploads\/sites\/30\/2018\/07\/19-1-225x97.png 225w, https:\/\/ebooks.inflibnet.ac.in\/itp7\/wp-content\/uploads\/sites\/30\/2018\/07\/19-1-350x151.png 350w\" sizes=\"auto, (max-width: 639px) 100vw, 639px\" \/><\/p>\n<p>Let us summarize the key concepts covered in this module<\/p>\n<ul>\n<li>Simple Programming in R<\/li>\n<li>Using Loops and Decision statements<\/li>\n<li>Using Graphics<\/li>\n<li>Creating User Defined Functions<\/li>\n<\/ul>\n<table>\n<tbody>\n<tr>\n<td><strong>you can view video on R Programming &#8211; 2<\/strong><\/td>\n<td><a href=\"https:\/\/youtu.be\/r9PcMwmVkFo\" target=\"_blank\" rel=\"noopener\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone wp-image-120\" src=\"http:\/\/epgpbooks.inflibnet.ac.in\/wp-content\/uploads\/2018\/11\/download.png\" alt=\"\" width=\"36\" height=\"36\" \/><\/a><\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p><strong>References for R Programming:<\/strong><\/p>\n<ol>\n<li style=\"text-align: justify;\">Felix Alvaro. <em>R\u202f: Easy R programming for beginners, your step-by-step guide to<\/em> <em>learning R programming<\/em>,<\/li>\n<li style=\"text-align: justify;\">John Braun and Duncan James Murdoch. <em>A first course in statistical programming<\/em> <em>with R<\/em>,<\/li>\n<li style=\"text-align: justify;\">John M. Chambers. 2008. <em>Software for data analysis\u202f: programming with R<\/em>, Springer.<\/li>\n<li style=\"text-align: justify;\">Michael J. Crawley. <em>The R book<\/em>,<\/li>\n<li style=\"text-align: justify;\">Tilman M. Davies. <em>The book of R\u202f: a first course in programming and statistics<\/em>,<\/li>\n<li style=\"text-align: justify;\">Mark. Gardener. 2012. <em>Beginning R\u202f: the Statistical Programming Language.<\/em>, John Wiley &amp; Sons.<\/li>\n<li style=\"text-align: justify;\">Colin (Colin Stevenson) Gillespie and Robin Lovelace. <em>Efficient R programming\u202f: a<\/em> <em>practical guide to smarter programming<\/em>,<\/li>\n<li style=\"text-align: justify;\">Garrett Grolemund. <em>Hands-on programming with R<\/em>,<\/li>\n<li style=\"text-align: justify;\">Thomas Mailund. <em>Advanced Object-Oriented Programming in R\u202f: Statistical\u00a0<\/em><em style=\"text-align: initial; font-size: 1em;\">Programming for Data Science, Analysis and Finance<\/em><span style=\"text-align: initial; font-size: 1em;\">,<\/span><\/li>\n<li style=\"text-align: justify;\">Norman S. Matloff. 2011. <em>The art of R programming\u202f: tour of statistical software<\/em> <em>design<\/em>, No Starch Press.<\/li>\n<li style=\"text-align: justify;\">Shuichi Ohsaki, Jori Ruppert-Felsot, and Daisuke Yoshikawa. <em>R programming and its<\/em> <em>applications in financial mathematics<\/em>,<\/li>\n<li style=\"text-align: justify;\">Kun Ren. <em>Modern R programming cookbook\u202f: recipes to simplify your statistical<\/em> <em>applications<\/em>,<\/li>\n<li style=\"text-align: justify;\">Kun Ren. <em>Learning R programming\u202f: become an efficient data scientist with R<\/em>,<\/li>\n<li style=\"text-align: justify;\">Omar. Trejo and Peter. C. Figliozzi. 2017. <em>R Programming By Example Practical,<\/em> <em>hands-on projects to help you get started with R.<\/em>, Packt Publishing.<\/li>\n<li style=\"text-align: justify;\">Alain F. Zuur, Elena N. Ieno, and Erik. Meesters. 2009. <em>A beginner\u2019s guide to R<\/em>, Springer.<\/li>\n<li style=\"text-align: justify;\">Anon. R: The R Project for Statistical Computing. Retrieved March 19, 2017 from https:\/\/www.r-project.org\/<\/li>\n<\/ol>\n","protected":false},"author":4,"menu_order":33,"template":"","meta":{"_acf_changed":false,"pb_show_title":"on","pb_short_title":"","pb_subtitle":"","pb_authors":["mr-hardik-joshi"],"pb_section_license":""},"chapter-type":[],"contributor":[58],"license":[],"class_list":["post-475","chapter","type-chapter","status-publish","hentry","contributor-mr-hardik-joshi"],"part":3,"_links":{"self":[{"href":"https:\/\/ebooks.inflibnet.ac.in\/itp7\/wp-json\/pressbooks\/v2\/chapters\/475","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/ebooks.inflibnet.ac.in\/itp7\/wp-json\/pressbooks\/v2\/chapters"}],"about":[{"href":"https:\/\/ebooks.inflibnet.ac.in\/itp7\/wp-json\/wp\/v2\/types\/chapter"}],"author":[{"embeddable":true,"href":"https:\/\/ebooks.inflibnet.ac.in\/itp7\/wp-json\/wp\/v2\/users\/4"}],"version-history":[{"count":5,"href":"https:\/\/ebooks.inflibnet.ac.in\/itp7\/wp-json\/pressbooks\/v2\/chapters\/475\/revisions"}],"predecessor-version":[{"id":725,"href":"https:\/\/ebooks.inflibnet.ac.in\/itp7\/wp-json\/pressbooks\/v2\/chapters\/475\/revisions\/725"}],"part":[{"href":"https:\/\/ebooks.inflibnet.ac.in\/itp7\/wp-json\/pressbooks\/v2\/parts\/3"}],"metadata":[{"href":"https:\/\/ebooks.inflibnet.ac.in\/itp7\/wp-json\/pressbooks\/v2\/chapters\/475\/metadata\/"}],"wp:attachment":[{"href":"https:\/\/ebooks.inflibnet.ac.in\/itp7\/wp-json\/wp\/v2\/media?parent=475"}],"wp:term":[{"taxonomy":"chapter-type","embeddable":true,"href":"https:\/\/ebooks.inflibnet.ac.in\/itp7\/wp-json\/pressbooks\/v2\/chapter-type?post=475"},{"taxonomy":"contributor","embeddable":true,"href":"https:\/\/ebooks.inflibnet.ac.in\/itp7\/wp-json\/wp\/v2\/contributor?post=475"},{"taxonomy":"license","embeddable":true,"href":"https:\/\/ebooks.inflibnet.ac.in\/itp7\/wp-json\/wp\/v2\/license?post=475"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}