Finding the column number of the smallest element in a certain row
问题 Using R Say for example you have a matrix such as the one below. > C<-matrix(c(0,-7,2,8,0,0,3,7,0,3,0,3,0,0,0,0),nrow=4,byrow=TRUE) > C [,1] [,2] [,3] [,4] [1,] 0 -7 2 8 [2,] 0 0 3 7 [3,] 0 3 0 3 [4,] 0 0 0 0 How do you find the column number of the smallest element in a certain row. For example I want to know what column number the smallest element in row 1 is. Therefore the output should just be 2. As the smallest element in row 1 is -7 and that is in column 2. I'm assuming the answer is