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

Randi Chen (CHEN@hhp.hawaii-health.com)
Wed, 21 Oct 1998 09:50:43 HST

Dear S+ Users,

I have a matrix say, x (5x5).

x
1 6 11 16 21
2 7 12 17 22
3 8 13 18 23
4 9 14 19 24
5 10 15 20 25

Then
x.list<-x[col(x)<row(x)]

will give me a list of all the elements of the
low triangular off diagnal matrix of x

x.list

2 3 4 5 8 9 10 14 15 20

After some manipulation of x.list, I want to put these elements back to
their original position, low triangular, in x.

So I did the following. It works, but tedious I feel.
"The old programming idea: looping"

Do you think S+ has an inverse-function for "x[col(x)<row(x)]"?

The following is my code to do this.

If S+ does have a simpler function to do this, please let me know.

A lot of thanks in advance!

x.list
[1] 2 3 4 5 8 9 10 14 15 20
> cumlow<-NULL
> for (j in 1:(5-1))
+ {
+ r0<-c(rep(0,j),x.list[1:(5-j)])
+ x.list<-x.list[(5-j+1):length(x.list)]
+ cumlow<-rbind(cumlow,r0)
+ w<-matrix(rbind(cumlow,rep(0,5)),ncol=5,byrow=T)
+ }
>
>
> w
[,1] [,2] [,3] [,4] [,5]
[1,] 0 0 0 0 0
[2,] 2 0 0 0 0
[3,] 3 8 0 0 0
[4,] 4 9 14 0 0
[5,] 5 10 15 20 0

Randi Chen

Randi Chen

Hawaii Center for Health Research
846 S. Hotel Street Suite 306
Honolulu, Hawaii 96813
(808)-524-3595 (voice)
(808)-524-4315 (fax)

e-mail: Chen@hhp.hawaii-health.com
-----------------------------------------------------------------------
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