Re: [R] Help with avoiding For Loop

From: Anup Menon <anup.nandialath_at_gmail.com>
Date: Fri, 21 Nov 2008 13:42:49 -0500

Dear Jorge,

Thanks a lot.

Regards

Anup

On Thu, Nov 20, 2008 at 10:19 PM, Jorge Ivan Velez <jorgeivanvelez_at_gmail.com
> wrote:

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



R-help_at_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. Received on Fri 21 Nov 2008 - 18:46:38 GMT

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Fri 21 Nov 2008 - 19:31:23 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-help. Please read the posting guide before posting to the list.

list of date sections of archive