On Tue, Dec 9, 2008 at 11:52 PM, Charles C. Berry <cberry@tajo.ucsd.edu>wrote:

> The 'better way' to do almost anything starts with a reading of the
> _posting guide_, which reminds you to
>        Do your homework before posting [Reasons whyfor deleted]]...
>


> Oh yes, if you are too lazy to look up the posting guide URL, the function
> help.request() will open it for you when you admit that you haven't yet read
> it (or lead you thru the further steps to prepare a question to this list if
> you say that you have read it).


Charles, I am distressed by the nasty tone of your note.  Though I certainly
agree that poor queries on this list are an annoyance, and that the posting
guide gives useful advice on what to do before posting, I don't think that
poor queries are a reason to presume bad faith for any but the most flagrant
correspondents ("here is my problem set, solve it for me").  And though I
have not been on this list very long, I have been answering questions on
other lists like this for a long time.

What's more, it seems to me that Witthoft has a legitimate problem.  I tried
to solve it myself, and here is what I come up with:

test <- matrix(rnorm(20),ncol=2)

which.max(dist(x),arr.ind=TRUE)
     => Error, though which supports arr.ind, which.max doesn't
        Yes, that is documented, but it violates reasonable expectations.

which(dist(x)==max(dist(x)),arr.ind=TRUE)
     => 21  oops, that is a vector index; what about arr.ind?
        Apparently the dist class (return class of dist fnc.)
        doesn't act as an array here (and which/arr.ind is
        happy to treat a vector as an array without warning).
        Is this a problem in dist, or a problem in which?
        So how do I map back from 21 to 3,7?  Nothing obvious.
        ? `[`, ? array, and ? dist don't seem to help.

So let's convert to a matrix explicitly:

which(as.matrix(dist(x)==max(dist(x))),arr.ind=TRUE)
     =>      row col
         [1,] 21   1
        Hmm, that's not right; apparently the == flattened the
        dist class into its base vector, which which/arr.ind
        helpfully (?) treated as a matrix.

which(as.matrix(dist(x))==max(dist(x)),arr.ind=TRUE)
    =>        row col
          7     7   3
          3     3   7
        Finally getting useful results; but converting to the array
        added in the upper triangular part... oh, well, we need to
        choose *which* maximum anyway.

So, as Witthoft said: what's a better, or cleaner way to do all this?  And
why aren't R's operators more regular in their behavior?  Why doesn't
arr.ind work for which.max?  Why doesn't dist(x)==1 return an object of the
same shape as the original dist (as matrix(...)==1 would have), but instead
flatten it?  Where does one find the function that maps from a list of array
indices to the corresponding vector index and vice versa?

             -s

	[[alternative HTML version deleted]]

