Re: [R] Help with avoiding For Loop

2008-11-21 Thread Anup Menon
),2,function(x) > c(Mean=mean(x),Var=var(x > > > HTH, > > Jorge > > > > On Thu, Nov 20, 2008 at 10:09 PM, Anup Menon <[EMAIL PROTECTED]>wrote: > >> Dear Friends, >> >> I'm trying to see if there is some possibility that I can do the fol

Re: [R] Extracting diagonal matrix

2008-11-21 Thread Anup Menon
Hi Ezhil, Maybe this will help. There might be an easier way to do this but here is one solution. tril <- function(A) { A <- as.matrix(A) cmats <- matrix(rep(1,length(A)),dim(A)[1],dim(A)[2]) upper.tri(cmats,diag=T) cmats[upper.tri(cmats)] <- 0 out <- A*cmats return(out) } tril(correlation

[R] Help with avoiding For Loop

2008-11-20 Thread Anup Menon
Dear Friends, I'm trying to see if there is some possibility that I can do the following computations without a loop. I have attached a toy example below. A <- c(1,2,3,4,5) B <- rnorm(100) store <- matrix(0,5,2) for (i in 1:5) { store[i,1] <- mean(pnorm(A[i]*B)) store[i,2] <- var(pnorm(A[i]*