# Re: [S] Inverse function for x[col(x)<row(x)]

Prof Brian Ripley (ripley@stats.ox.ac.uk)
Thu, 22 Oct 1998 13:27:33 +0100 (BST)

> From: andrey@utstat.toronto.edu
>
> Randi Chen asks if S-Plus has a function which does the inverse
> of "x[col(x)<row(x)]". This operation is very similar to
> compressed storage of a symmetric matix. I am not aware of
> an explicit inverse function in S-Plus to do this.

As we seem to have a succession of replies, not all of which work, let
me make explicit that as I understand this the inverse function is to
subset the left-hand side of the assignment (implicitly using the "[<-"
function, which could be used explicitly):

z <- x[col(x)<row(x)]
do something to z
x[col(x)<row(x)] <- z

It really is as simple as that, the essence of Audrey's solution.

> x <- matrix(1:25, 5,5)
> z
[1] 2 3 4 5 8 9 10 14 15 20
> x[col(x)<row(x)] <- -z
> x
[,1] [,2] [,3] [,4] [,5]
[1,] 1 6 11 16 21
[2,] -2 7 12 17 22
[3,] -3 -8 13 18 23
[4,] -4 -9 -14 19 24
[5,] -5 -10 -15 -20 25

Puzzling, the original poster's solution does not do precisely what
he asked for (it creates a lower-triangular matrix, not replaces part of x).

```--
Brian D. Ripley,                  ripley@stats.ox.ac.uk
Professor of Applied Statistics,  http://www.stats.ox.ac.uk/~ripley/
University of Oxford,             Tel:  +44 1865 272861 (self)
1 South Parks Road,                     +44 1865 272860 (secr)
Oxford OX1 3TG, UK                Fax:  +44 1865 272595

-----------------------------------------------------------------------
This message was distributed by s-news@wubios.wustl.edu.  To unsubscribe
send e-mail to s-news-request@wubios.wustl.edu with the BODY of the
message:  unsubscribe s-news
```