I am trying to figure out how to create a loop that will take the
difference of each member of a vector from each other and also spit out
which one has the least difference.

I do not want the vector member to subtract from itself or it must be able
to disregard the 0 obtained from subtracting from itself.

For example:

x = c(17,19,23,29)

1. abs(x-x[1]) = (0, 2, 6, 12)

2. abs(x-x[2]) = (2, 0, 4, 10)

3. abs(x-x[3]) = (6, 4, 0, 6)

4. abs(x-x[4]) = (12, 10, 6, 0)

The code would then spit out that x[1] and x[2] are the least different,
but if there were 2 separate values that were equal the program would
recognize them as least different.

A little extra help would be to also make this go down row by row through
horizontal vectors.

I am new to R and all my for loops I'm trying come back null.

Thanks for any help.

	[[alternative HTML version deleted]]

