$21
Question 1: Familiar with your IDE By finishing this question correctly you will: 1. install R and RStudio and configure them on your own computer, 2. understand how to install and load R packages, 3. learn how to find documents for a function/package that you are not familiar with. Please complete all of the followings: • Download and install R and RStudio on your computer. They are both free online, available for Windows, Linux and Mac OS. • From Canvas, download and read RStudio101.pdf to get familiar with this IDE, learn the fundamental things such as how to install an R package. • In RStudio, go to “Tools→Global Options→Code Editing”, change “tab width” from 2 to 4. There may be different entry names for different operating systems. • Check “Highlight selected line”, “Highlight selected word” and “show line numbers”. • Create a new folder for this course, and set it as your working directory. • Load package ‘fBasics’, this is one of the default packages in R. • Install and load package ‘quantmod’, unlike fBasics, you need to download first. • Make a screen shot for your installation and loading package ‘quantmod’, and upload this screenshot with your code together. • In your source type “?basicStats” and learn how to use this function by yourself. Then run this function on the random variable “xx”, which you created before in the previous subquestion. • Try double question mark, “??basicStats” and see what you get. 1 Question 2: Basic data types • Three ways to create vector: – Of course the first and easiest way is using a colon. – With function seq(), Create a series named v1, from -10 to 10, by = 0.1, then print it out. – Create a STRING vector v2 = {‘0’, ‘1’, ‘2’, ‘0’, ‘1’, ‘2’, ‘0’, ‘1’, ‘2’ } using rep(). • Explicit conversion – Convert v2 to numeric and assign to a new variable v2num – Convert v2 to logical, what is the result? Assign the result to v2NA. – Convert v2num to logical and assign to v2logical. • Matrix and List – Create a 3 by 3 matrix based on v2num, byrow = T. Name your matrix m2. – m2 is a singular matrix, do something to make this matrix solvable, calculate and print the inverse matrix of m2. – Create a list called myFirstList, using v2, v2num, v2NA, v2logical and m2 as the elements. – Name these elements as “char”, “integer”, “NAs”, “bool” and “mat”. – Use two methods to subset the 4th element: by indexing and by element name. Question 3: Loops 2520 is the smallest number that can be divided by each of the numbers from 1 to 10 without any remainder. Use a loop to find out what is the smallest positive number that is evenly divisible by all of the numbers from 1 to 20? Question 4: ”apply” function Download C.csv from canvas, read this table in R and name it as C2008 and do following things • Create subtable which only contains Open, High, Low and Close • Using ”apply” function we mentioned in class to calculate mean value for each column and save it as a vector • Using ”apply” function we mentioned in class to calculate mean value for each row and save it as a 3 by 7 matrix, the data should be assigned by row. Please upload all code and necessary files showing that you have completed all questions. 2