ASSIGNMENT I Due Wednesday April 24. Preliminary Go through Chapter 1 and Appendix A of `An Introduction to R` available at `Help` in the R console. Type all the commands in Appendix A and study the outputs. Read Chapter 1 of Peter Dalgaard , Introductory Statistics with R, Second Edition, (2008) Springer, New York. Use the command `data()` and look at the data sets available at the console. On each use `head()`,`str()` and study their class. If data structure, use the usual data structure commands on them and familiarize yourself with as many as you can. The above need not be submitted. The coding assignments must be answered as in the following example. The code must be given in a *.txt file (not as a *.doc file) with a sample input or the input specified in the problem When the input and code are cut and pasted onto R console the desired Output must result. Example 1: Write a program to convert a vector of length 100 Into an array of dim = c(5,20). Answer x<- c(1:100) y<- array(x,dim=c(5,20));y Example 2: Take as input the `Nile` dataset in the R datasets package. Write a function to convert this into a dataframe with 5 columns) fN<- function(Nile) { y<- Nile; z<- data.frame(y); y1<-y[c(1:20)];y2<-y[c(21:40)];y3<-y[c(41,60)];y4<-y[c(61,80)];y5<-y[c(81,100)];zN=data.frame(cbind(y1,y2,y3,y4,y5));zN };fN(Nile) If you store this as a *.txt file and cut and paste it on to R console You get the response as a data frame with columns y1to y5 and 20 rows. For the coding part of the assignment, you will get credit only if, when your code is cut and pasted onto R, it gives the correct output. So please actually do this yourself to verify that the code works before you submit it. 1(a)Write a function to convert `Nile` into a dataframe with columns `1871-1890`,`1891-1910`,`1911-1930`,`1931-1950`,`1951-1970`. (This can come as X1871.1890 etc.) (Here the function is simply a compact way of collecting the sequence of commands required to carry out the task.) (b) Write a function to add to the above dataframe a column with name`level_year` and with rows 1..... 20 . The input to this function should still be `Nile`. (c) Write a function to add to the above data frame, a row called `means` containing the mean Of the cols . The input to this function should still be `Nile`. 2. x<- c(c(1:10),c(5:10),c(100:103)) Coding: (a) Write a function s(x) which takes x as input and produces a row y= k*x such that sum of entries of y is 1. (b) Write a function m(x) which takes x as input and produces a matrix with y as the first row and the others cyclically permuting y. Theory: (c) Find the eigen values of this matrix; (d) Taking this matrix as representing a markov chain, find its steady state probability distribution. 3.x<- c(1:100) Coding: (a) Write a function m2(x) which takes x as input and produces a 10x10 matrix with row one 1,2.. 10, row two 11,...20 and so on. (b) Write a function m3(m2) which takes m2 as input and replaces all entries above the diagonal by zeros. (c) Write a function m4(m2) which takes m2 as input and replaces all entries except diagonal, superdiagonal and subdiagonal by zeros. 4. x<- rnorm(200);y1=sin(x);y2=cos(x); y3=(y2+y1)/sqrt(2); y4=(y2-y1)/sqrt(2); (a)Plot (x,y1),(x,y2), (x,y3), (x,y4); in adjacent plots, as an array of 1x4 plots and of 2x2 plots. (b)Plot (x,y1),(x,y2),(x,y3),(x,y4); all in same graph, using different symbols and colours for each plot and give an appropriate legend to distinguish the plots. (c)Use persp() function to get a 3D plot of (a)z= x^2+y^2 (b) z= exp(x^2+y^2) (c)z= sinc(sqrt(x^2+y^2)) for x,y values from 0 to 1 in steps of 0.1. The above plots must be submitted as pdf files.