Question: You are expected to write a script, successfully run it in R-studio, and copy and paste the script and the final result showed in your
You are expected to write a script, successfully run it in R-studio, and copy and paste the script and the final result showed in your console window as text entry to turn in your homework on Canvas website. Late submission of your homework will not get credit. Instructions: Es 1, Generate a vector of 500 random numbers called "Data" from a normal distribution with the mean being 0, and standard deviation being 1. (hint: use "rnorm" function). 2. Generate a 500 by 1 matrix (use the "matrix" function) called "Marks" with all elements being 0. 3. Write a "for" loop to go through all 500 random numbers of "Data". For each number, if it is less than 1, do two things: (1) use "cat" to show a message saying that you find such a number, and (2) change the corresponding element in "Mark" from 0 to 1 (e.g., change the 11th number in Mark to 1 if the 11th element in Data is less than 1). Hint: use conditional statements inside the loop. 4, Calculate and show the sum of "Mark" (hint: use the "sum" function), which essentially shows how many of the 500 numbers are less than 1
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
