Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

) 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

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Advances In Knowledge Discovery In Databases

Authors: Animesh Adhikari, Jhimli Adhikari

1st Edition

3319132121, 9783319132129

More Books

Students also viewed these Databases questions