Question: ) Modify the my.largest function (created in Script 3.4) to create my.smallest which when given one column of a data frame returns the smallest value

  1. ) Modify the my.largest function (created in Script 3.4) to create my.smallest which when given one column of a data frame returns the smallest value in the column. Be sure to check for and print the number of NAs. Test your function using the following columns of the creditScreening dataset. USING R

For example, to find the number of NAs and the smallest value of column two:

> my.smallest(creditScreening[,2])

No. of NAs 12

The smallest value is:

[1] 13.75

  1. (2 Points) Column 3
  2. (2 Points) Column 8
  3. (2 Points) Column 11
  4. (2 Points) Column 14
  5. (2 Points) Column 15

# Script 3.4 Finding the Largest Value

my.largest <-function (x) # Find the largest value in x which is a column in a # data frame, array, or matrix. The function also prints # the total number of NAs in the column. # The assumption is the value of the first # item in x is not NA. { largest <- x[1] # initialize the largest value nas <- 0 # Initialize the number of NAs rows = length(x)-1

for (i in 2:rows) { if(is.na(x[i])) { nas=nas +1 } else { if(x[i]> largest) largest <- x[i] } } # End for # Print number of NAs cat("No. of NAs ",nas," ") # Return the largest value cat("The largest value is: ") # Return the largest value return(largest) } # End my.largest

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!