Question: Submit the compiled file ( docx , pdf , or html ) . 1 . Your file must includes your codes for Question # 1

Submit the compiled file (docx, pdf, or html).
1. Your file must includes your codes for Question #1,5,6,7.
2. Each script should be commented by Question Number, such as #Question 1 prior to each of the coding.
3. The script should be compiled successfully.
#1 Write a new function called MyVectorInfo() that takes as input a vector and returns the key characteristics of vector, such as the min, the max, and the mean of the vector. Make sure to give careful thought about the parameters you will need to pass to your function and what kind of data object your function will return.
# HINT: If you are not sure how to start, use ALL the functions listed below (there are other ways doing this):
function(myVector);return();c(); which.max; mean; which.min; MyVectorInfo;<- ;{}
============================================
myVector <- c(1,2,3,4,5,6,7,8,9,10)
# define a new function "MyVectorInfo"
MyVectorInfo <-function(,...)
{
min <-(vector)
max <-(vector)
mean <-mean(vector)
(c(min, max, mean))
}
MyVectorInfo(myVector)
#5
Complete the script by populating the empty space to produce the output shown.Pay attention to the space holder vs. actual call of an object. For the first two boxes, do not write in numbers. They should be an object name or a space holder name (either y or p).
Code:
y <-3.4321
new_round <-function(p, digits =1){round(, digits)}
c(new_round(), new_round(y, digits=))
Output:
3.4003.432
#6
Complete a function by replacing *[answer1]* with a base R function you've learned this week that gives random numbers when throwing a fair die.
Hint 1: In side your function, you may want to use sample function to randomly select one number from a die. Hint 2: The outcome will be like this: **since it is a random number, you will see different value in your scree.
throw_die()
[1]2
throw_die()
[1]5
throw_die()
[1]1
#Your function to complete.
throw_die <- function(){
number <-[answer1](1:6, size =1)
number
}
#7
Watch the assigned video, and practice the content. Then, write a function, named worstWithIndex() that will print the name of the car that has the worst mpg. This function will take column index as an input.
For example, when you successfully write the function and run the function using the first index like below, the result should be like this:
worstWithIndex(1)
"Cadillac Fleetwood"
Write (or complete) your function by populating the yellow highlighted parts below:
worstWithIndex <- function(col.index,){
index <-[ Select ]["which.min", "max", "min", "which.max"](mtcars[ Select ][",col.index", "col.index,", "mtcars$mpg"])
rnames <-[ Select ]["", "colnames", "mtcars$mpg", "rownames", ",col.index"](mtcars) #read the row names of mtcars object
car <-rnames[ Select ]["mtcars", "index", "index, 4"]
return(car)
}

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!