Question: Write a short R function called missingMaxMin that accepts two paramters: a . A vector of numbers called InputNumbers, some of which may be missing

Write a short R function called missingMaxMin that accepts two paramters:
a. A vector of numbers called InputNumbers, some of which may be missing (i.e. NA)
b. An indicator variable MaxMin which has a value of either 1 or 2
i. If MaxMin is 1, missing values in InputNumbers are replaced with the maximum value in InputNumbers
ii. If MaxMin is 2, missing values in inputNumbers are replaced with the minimum value in InputNumbers
So for instance
x <- c(1.2,7.9,3.4, NA,4.2,9.1, NA)
z <- missingMaxMin(x,1) #MaxMin is 1, so replace NAs with the maximum
z would now contain (1.2,7.9,3.4,9.1,4.2,9.1,9.1)
hint = remember to use the na.rm=T parameter when determining the max or min

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 Databases Questions!