R语言代写

1. Write a short comment about what this R script is about.
2. Remove all existing objects in your “environment”.
3. Create a vector called “HousePrices”, which consists of 100 random numbers
generated from a Normal distribution, mean and the standard deviation of
which are 300,000 and 50,000 respectively. Hint: use function “norm” to
generate random numbers from a Normal distribution. Note that you cannot
have “” in your numbers when you write R codes. For example, you cannot
write X=1,000,000 if you want to let X equal 1 million. You should simply
write X=1000000.
4. Create a matrix called “TooLow”, which consists of 100 rows and 1 column. All
numbers of this matrix are O. Hint: use the “matrix” function and the input
data can be just 0 (e.g., data=0) since all numbers are identical.
5. Create a matrix called “TooHigh”, which consists of 100 rows and 1 column. All
numbers of this matrix are also O.
6. Write a “for” loop to go over each number inside “HousePrices”, from the 1st
one to the 100th For each number, do the following things.
1. Write a conditional statement. If the number is less than 10,000, do two
things: (1) change it to 10,000 (Hint: If you want to change the ith number
of a vector X from whatever it is to 99, the code would be Xli]=99); (2)
Change the ith number of “TooLow” to 1 (Hint: TooLowli)=1. Since there is
only one column, TooLow[1,1] is the same with TooLow(il).
2. Write another conditional statement. If the number is greater than
1,000,000, do two things: (1) change it to 1,000,000; (2) Change the ith
number of “TooHigh” to 1.
7. Calculate the summary of “TooLow”. Hint: sum (TooLow). This will tell you how
many numbers in the original “HousePrices” are less than 10.000.
8. Calculate the summary of “TooHigh”. This will tell you how many numbers in
the original “HousePrices” are more than 1.000.000