Hi
Well, I would prefer tapply so I will let **you** construct for loop
for the calculation.
x <- rpois(100, 3)
y <- rep(1:ceiling(length(x)/12),each=12)
tapply(x,y[1:100],sum)
1 2 3 4 5 6 7 8 9
38 37 40 29 36 31 47 46 16
HTH
Petr
On 9 Oct 2006 at 15:23, Bikash Jain wrote:
Send reply to: "Bikash Jain" <bjain@bslindia.com>
From: "Bikash Jain" <bjain@bslindia.com>
To: <s-news@lists.biostat.wustl.edu>,
<s-news@wubios.wustl.edu>
Subject: [S] For loop
Date sent: Mon, 9 Oct 2006 15:23:15 +0530
> Hi,
>
> I have generated 100 random numbers from the poisson distribution
> using the following command :
>
> rpois(100, 3)
>
> [1] 1 2 4 5 3 2 4 4 3 4 3 7 4 2 3 6 2 3 3 8 5 2 4 6 1 2 3 6 5 3 3 4 5
> 0 3 1 6 1 1 8 0 0 1 3 5 4 3 2 2 2 2 7 2 2 4 5 5 5 4 3 2 1 3 3 5 1 3 3
> 2 5 2 4 5 3 3 9 2 4 1 3 4 3 3 2 3 3 1 2 1 5 4 3 6 2 3 1 1 [98] 3 3 3
>
> I want to use the for loop to calculate the sum of first 12 numbers
> (i.e 1 to 12) followed by the sum of another 12 numbers (13 to 25)
> and so on from the above numbers generated. Please let me know the
> commands to write the for loop for the same.
>
> Thank you and Best Regards,
>
> Bikash Jain
> Manager-Technical
> Binary Semantics Limited
> Plot No. 38, Electronic City
> Sector-18
> Gurgaon-122015
> Haryana, India
>
> Phone : +91-124-2397660 Xtn: 239
> Cell : 9818250173
> Web : http://www.binarysemantics.com
>
>
> --------------------------------------------------------------------
> This message was distributed by s-news@lists.biostat.wustl.edu. To
> unsubscribe send e-mail to s-news-request@lists.biostat.wustl.edu with
> the BODY of the message: unsubscribe s-news
Petr Pikal
petr.pikal@precheza.cz
|