Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Directions: All of this assignment should be done using R. All homework will be submitted electronically. Follow hw guide.pdf on myCourses for instructions on assignment

Directions: All of this assignment should be done using R. All homework will be submitted electronically. Follow hw guide.pdf on myCourses for instructions on assignment submission. Note that for this assignment only, the only file that is to be submitted is the .R file, as there are no questions to answer.

1) The file attached to this assignment is called max_col.R. This .R file contains a function called max.col, which finds the column with the maximum sum in a matrix and returns that column number and its sum. For this assignment, modify this function to create a new function called min.row, which will identify the row with the smallest sum. This function MUST include the if statement and for loop in max.col.

2) To ensure your code is working correctly, once you have finished, you should run these 3 lines of code to verify your function works properly:

set.seed(10)

datamat <- matrix(rnorm(1000),ncol=10,byrow=T)

min.row(datamat)

You can verify by hand that the position you selected is the correct position.

Information below is what was given to us in .R document

max.col <- function(x) {

## The object x is a matrix that will ## be used to find the maximum column ## sum.

for (i in 1:dim(x)[2]) { ## Loop over the columns

if (i == 1) { max.col <- sum(x[,i]) max.col.num <- i } else if (sum(x[,i]) > max.col) { max.col <- sum(x[,i]) max.col.num <- i }

} ## End the loop over the columns

print(paste("The column with the maximum sum is ",max.col.num," and its sum is ",max.col,".",sep=""))

} ## End the function max.col

Here is the file if that helps

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

More Books

Students also viewed these Databases questions