Skip to content

(no subject)

2 messages · Jeremie Juste, Bert Gunter

#
Hello,

Be sure to include the mailing list,<r-help at r-project.org> when you
reply. In this way to improve your chances of obtaining a good answer
and everyone benefits. 


May be something like this ?

aa <- matrix(1:9,3,3)
matrix(as.numeric(aa)[!as.numeric(aa) %in% diag(aa)],2,3)

     [,1] [,2] [,3]
[1,]    2    4    7
[2,]    3    6    8

Hope it helps,

Jeremie

malika yassa <yassa_malika at yahoo.fr> writes:
#
Jeremie's suggestion of course will fail if some of the off-diagonal
elements are the same as those on the diagonals.

The request doesn't make a lot of sense to me, but if "m" is the matrix,

 m[row(z) != col(z)]

reliably extracts the vector of non-diagonal entries, which can then be
dimensioned as desired.
Or upper.tri() and lower.tri() can be used to separately extract the upper
and lower triangle entries via logical indexing.

Cheers,
Bert


Bert Gunter

"The trouble with having an open mind is that people keep coming along and
sticking things into it."
-- Opus (aka Berkeley Breathed in his "Bloom County" comic strip )


On Sat, Oct 20, 2018 at 8:48 AM Jeremie Juste <jeremiejuste at gmail.com>
wrote: