[R] lower triangle
Wilkinson, Mark
Mark.Wilkinson at stjude.org
Fri Dec 20 21:00:07 CET 2002
Hi,
I want to compute the lower triangle of a square matrix (optionally, sans
diagonal). With for() loops I can do something like this:
## 5 by 5 matrix rtn
for (j in 1:5) {
for (k in 1:j) {
if (j != k) { ## optional
rtn[j, k] <- my.func(j, k)
}
}
}
I'd like to do this with apply(). Is there some way I can do this kind of
'short-circuit'?
Thanks,
Mark Wilkinson
Informatics Analyst
St. Jude Children's Research Hospital
Department of Pharmaceutical Sciences
More information about the R-help
mailing list