s-news
[Top] [All Lists]

[S] filling a sparse matrix

To: "s-news (E-mail)" <S-news@wubios.wustl.edu>, "'s-nieuws'" <s-nieuws@candiensten.nl>
Subject: [S] filling a sparse matrix
From: Siem Heisterkamp <s.h.heisterkamp@amc.uva.nl>
Date: Thu, 21 Jan 1999 09:11:07 +0100
Sender: owner-s-news@wubios.wustl.edu


Dear,
Many bright people here!
 I wrote:
Siem> dear S-Plus users, What do I wrong? I try to fill a sparse
  Siem> matrix. Suppose I have a (large) matrix n*k X and data resid
  Siem> unequal zero of length m.  I also have row.num and col.num
  Siem> both of length m indicating each element of which row and
  Siem> collumn corresponds with a value of resid.  I thought to be
  Siem> clever, using the assignment :

  Siem> X[row.num, col.num]<-resid[1:m]
 
I counted more than 14 answers (stopped counting..) all giving the
similar answer (some with empirical evidence) :
Try this:
          X[cbind(row.num, col.num)] <- resid[1:m]

Thanks!

Dr. S.H. Heisterkamp
University of Amsterdam
Department of Clinical Epidemiology and Biostatistics
room J2-220
PO Box 22700 1100 DE Amsterdam
tel: +31-(0)-20-5668520
fax:+31-(0)-20-6912683
s.h.heisterkamp@amc.uva.nl

-----------------------------------------------------------------------
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

<Prev in Thread] Current Thread [Next in Thread>
  • [S] filling a sparse matrix, Siem Heisterkamp <=