Dear Anup,
Try this:
# Data
A <- c(1,2,3,4,5)
B <- rnorm(100)
# Results
t(apply(sapply(A,function(x) pnorm(x*B)),2,function(x)
c(Mean=mean(x),Var=var(x))))
HTH,
Jorge
On Thu, Nov 20, 2008 at 10:09 PM, Anup Menon
<anup.nandialath@gmail.com>wrote:
> 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]*B))
> }
> store
>
> Thanks in advance for your help.
>
> Kind Regards
>
> Anup
>
> [[alternative HTML version deleted]]
>
> ______________________________________________
> R-help@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide
> http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>
[[alternative HTML version deleted]]