$24
Submission Instructions
Total Points: 5 bonus points on HW1 if you submit this assignment and follow all instructions correctly on HW1
Make sure you clearly list each team member's names and Unity IDs at the top of your submission.
Your submission should be a single zip le containing your code and a README le with running instructions. Please follow the naming convention for your zip le: G(hw group no:) HW (hw no:), e.g. G1 HW 0. Your code should be named hw0:R.
Failure to follow naming conventions or programming related instructions speci ed below may result in your submission not being graded.
If the instructions are unclear, please post your questions on piazza.
Programming related instructions
Carefully read what function names have been requested by the instructor. In this homework or the following ones, if your code does not follow the naming format requested by the instructor, you will not receive credit.
For each function, both the input and output formats, as well as an example will be provided. Please ensure that you follow the correct input and output formats. Once again, if you do not follow the format requested, you will not receive credit.
Apart from library functions (library/require), seed function, comments and function de nitions, your code le should not contain any other function calls/code. If you wish to verify the correctness of your functions, do so in another le which does not need to be submitted. You are welcome to write your own helper sub-functions, but they should be called from within the TA-requested functions only.
DO NOT set working directory (setwd function) or clear memory (rm(list=ls(all=T))) in your code. TA(s) will do so in their own auto grader.
The TA will have an autograder which will rst run source(hw0.R), then call each of the functions requested in the homework and compare with the correct solution.
Your code should be clearly documented.
Software Installation
The TA(s) will be using the following software throughout the course unless otherwise stated.
R Version: Microsoft Revolution R Version 3.5.1.
Operating System: Ubuntu 16.04 or Ubuntu 18.04
1
ALDA { Spring 2019 Homework 1
R IDE: R Studio Desktop (free version)
If you do not already have the version of R and R Studio speci ed above, download and install them on your machine. If you already have an older version of R that you do not wish to update, we recommend setting up a virtual machine with the operating system speci ed above. If you are facing trouble installing R or RStudio, visit the TAs during their o ce hours. Ensure that the packages you use are compatible with the given version of R.
Learning Goals
By the end of this exercise, you should:
have installed all the necessary softwares required for this course homeworks. have explored R data types and data structures.
be able to create functions in R based on user requirements. have explored visualization techniques in R.
be able to create executable code in R.
be familiar with submitting programming assignments for this course.
Problems
(Krishna Gadiraju) In this homework, you will be creating two functions named intro to r and intro to plotting. You are already provided hw0:R template. Using the information provided below, complete the functions in the template. The input, output arguments and their types as well as function requirements have been discussed below. (Note the lower case notation). The variable names and types are given the format [variable name : data type]. Read up on the di erence between vectors, lists, named lists and data frames in R before you start this problem.
Note 1: double vector means a vector of type double.
Note 2: set seed to 123.
intro to r: Create a function called intro to r which will take an input (num values). Your function should create a random vector of size num values named new vector and should calculate the mean (new mean), median (new median), max (new max) and min (new min) values of this vector. You will then return a list in the following order [new vector, new mean, new median, new max, new min]. Input and output data types are described in further detail below.
Input: num values : integer
Output: a list: [new vector : double vector, new mean : double, new median : double,
new max : double, new min : double]
Example: intro to r(10) should generate a random array of size 10 and of type double, calculate its mean, median, max and min and return these values in the format speci ed above.
intro to plotting: Create a function called intro to plotting which will take an input (num values). Create a random vector of size num values named new vector. Using new vector, generate three plots as shown below. Use the ggplot2 package for plotting.
Plot 1: Scatter plot with new vector on x-axis and new vector on y-axis. Programmatically save this plot as teamID plot01:pdf
Plot 2: Scatter plot with new vector on x-axis and new vector2 on y-axis. Programmatically save this plot as teamID plot02:pdf
Example: intro to plotting(100)
You are allowed to use the prede ned functions de ned in R Base and ggplot2 for random array generation, max, min, mean and median and plotting operations.
2