This assignment contains two parts, here's part 1, 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...

1 answer below »

This assignment contains two parts, here's part 1,


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.


here's part 2,


First, import “A-04-C-DirtyData.csv” into R (hint: use read.csv) as an object “old.data”. Note that each row is for a person, and the three columns are for height (in feet), weight (in pounds), and income (in $).


Second, create a new object called “new.data” which contains only rows in the “old.data” without any missing values (NA) for any of the three variables, and with height between 4.5 and 6.5, weight between 80 and 200, and income between 40,000 and 200,000 (hint: create a “mark” matrix first; then write a loop; in each round of the loop, write conditional statements to mark good (or bad) rows; after the loop is done and all good (or bad) rows are marked, use which() to create “new.data”).


Third, use the dim function to show the dimension of “new.data”.


Finally, save “new.data” as a new csv file with the name “cleandata.csv” back to the same course folder (hint, use write.csv).


Copy and paste R script as text entry and the result of the dim function (copy from your console window and paste as text entry) to turn in your work.

Answered 1 days AfterJan 29, 2022

Answer To: This assignment contains two parts, here's part 1, 1, Generate a vector of 500 random numbers called...

Suraj answered on Jan 30 2022
121 Votes
SOLUTION.PDF

Answer To This Question Is Available To Download

Related Questions & Answers

More Questions »

Submit New Assignment

Copy and Paste Your Assignment Here