I found this example in an Introductory R book in the chapter on Matrices and Arrays
The array is > m [,1] [,2] [,3] [,4] [,5] [1,] 0 12 13 8 20 [2,] 12 0 15 28 88 [3,] 13 15 0 6 9 [4,] 8 28 6 0 33 [5,] 20 88 9 33 0 The code is #returns the minimum value of d[i,j], i !=j and the row attaining #the minimum, for square symmetric d; no special policy on ties mind <- function(d) { n <- nrow(d) # add a column to identify row number for apply() dd <- cbind(d,1:n) wmins <- apply(dd[-n,],1,imin) # wins will be 2 X n, 1st row being indices and 2nd being values i <- which.min(wmins[2,]) j <- wmins[1,i] return(c(d[i,j],i,j)) } #this finds the location, value of the minimum in a row x imin <- function(x) { lx <- length(x) i <- x[lx] # original row number j <-which.min(x[(x+1):(lx-1)]) k <- i+j return(c(k,x[k])) } The result s/b [1] 6 3 4 I am getting: Warning messages: 1: In (x + 1):(lx - 1) : numerical expression has 6 elements: only the first used 2: In (x + 1):(lx - 1) : numerical expression has 6 elements: only the first used 3: In (x + 1):(lx - 1) : numerical expression has 6 elements: only the first used 4: In (x + 1):(lx - 1) : numerical expression has 6 elements: only the first used I have check my typing a number of times. Does anyone see an error? Thanks, Jim L. [[alternative HTML version deleted]] ______________________________________________ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.