| To: | S-news list <s-news@lists.biostat.wustl.edu> |
|---|---|
| Subject: | vectorizing |
| From: | Catalina Mesina <cmesina@cs.vu.nl> |
| Date: | Thu, 31 Oct 2002 13:51:16 +0100 |
Dear List,
I need to make a function like:
makefun-function(data,m,n){
mat <- matrix(0,m,n)
u1 <- data[,1]
u2<-data[,2]
u3<-data[,3]
for(i in (1:m)) {
for(j in (1:n)) {
mat[i,j] <- sum(u1[(u2 == i & u3==j)])}}
mat
}
How can I write a vectorized version of this function? The above function is
slow for large data sets.
Thanks,
Catalina
|
| <Prev in Thread] | Current Thread | [Next in Thread> |
|---|---|---|
| ||
| Previous by Date: | Re: all possible combinations of predictors, Frank E Harrell Jr |
|---|---|
| Next by Date: | New home for S Poetry, Patrick Burns |
| Previous by Thread: | error.bar(): plotting errors on semi-log plots, Prins, N.H. (Klaas) |
| Next by Thread: | New home for S Poetry, Patrick Burns |
| Indexes: | [Date] [Thread] [Top] [All Lists] |