Question: Make my.largest (created in Script 3.4 BELOW) a function in your global environment. The file creditScreening.csv contains 690 instances which will be used for several
- Make my.largest (created in Script 3.4 BELOW) a function in your global environment. The file creditScreening.csv contains 690 instances which will be used for several examples later in the course. Use the function to find the number of NAs and the largest value in the following columns of creditScreening. USING R-STUDIO
For example, to find the number of NAs and the largest value of column two:
> my.largest(creditScreening[,2])
No. of NAs 12
The largest value is:
[1] 80.25
- (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
Get step-by-step solutions from verified subject matter experts
