# Title: Function in R # Student name 1: # Student name 2: # Comments (e.g, known bugs, questions you would like Dr. Cao to go through in the class, etc): #1. Write a function f1 which has two parameters n1 and n2, and it will return the summation of n1 and n2. Verify your function, for example, f1(10,20) should return 30. #2. Write a function Triangle which has one parameter n, it will print a Triangle of stars with nxn. By default, n is set to 3. For example, calling Triangle(3) or Triangle() will print the following: # * # * * # * * * #3. Use rnorm function to generate 1000 random numbers with mean 0 and standard deviation 1, save it to vector data1. And generate another 1000 random numbers with mean 10 and standard deviation 10, save it to vector data2. #4. Create a list mylist with data1 and data2 generated in previous question. #5. Use lapply function to calculate the max, min, mean, and median of two elements in mylist #6. Use Cor function to calculate the pearson correlation between data1 and data2. #7. Write a function fSquare with one parameter n and return square of n. For example, fSquare(3) will return 9. #8. Apply fSquare function to each element of data1 and store it to data1Square, also get data2Square with each element is square of element in data2. Calculate the pearson correlation between data1Square and data2Square, is that result the same as Question #6? #9. Write a function fOdd which has one parameter n as a vector, it will check each element in the vector and print the odd numbers in the vector. Usually we could use modulus to check if a number is odd or not, in R, i%%2 would be 1 if i is odd. For example, fOdd([1,3,2,423,54,2]) will print 1,3,423 #10. Write a function fMulti3 which takes one parameter n, it will print the multiples of 3 from 3 to n. For example, fMulti3(10) will print 3, 6, 9.