Using R
Say, for example, you have a matrix like 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 particular row. For example, I want to know which column number has the smallest element in row 1. Therefore, the output should be 2. Since the smallest element in row 1 is -7 and is in column 2. I assume that the answer is very simple, but I just donβt I can do it! I tried to do the following, but that just gives me an answer of 5.
> inds = which(C == min(C[1,])) > inds [1] 5
Can someone tell me what 5 means in this particular case?
thanks
algorithm matrix r which
calculator
source share