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
- ) 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
- (2 Points) Column 3
- (2 Points) Column 8
- (2 Points) Column 11
- (2 Points) Column 14
- (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
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started