Well, in fact, I did know that. And one can extract elements from a
matrix using a dim()-dimensional matrix of logical values, and .... lots
of ways. I wanted to use a vector. Your approach is likely faster, I
admit.
I'll refrain from comment on your "users" versus "programmers" remark.
Brad
-----Original Message-----
From: Dave Krantz [mailto:dhk@paradox.psych.columbia.edu]
Sent: Wednesday, November 07, 2007 11:45 AM
To: Biggerstaff, Brad J. (CDC/CCID/NCZVED)
Cc: dhk@paradox.psych.columbia.edu
Subject: Re: [S] Extracting Elements from a matrix
What you don't know is that elements of a matrix can be extracted by
using a two-column matrix index, the first column specifying the row and
the second the column.
Thus, your problem is solved by setting Index <- cbind(1:5, pos) and
then matrix.name[Index].
This is a feature of S (and R) not widely known among users, though it
is well known by programmers.
Dave Krantz (dhk@columbia.edu)
|