s-news
[Top] [All Lists]

Re: For loop

To: "Petr Pikal" <petr.pikal@precheza.cz>, "Bikash Jain" <bjain@bslindia.com>, <s-news@lists.biostat.wustl.edu>, <s-news@wubios.wustl.edu>
Subject: Re: For loop
From: "Lambert.Winnie" <lambert.winnie@ensco.com>
Date: Mon, 9 Oct 2006 10:13:37 -0400
Thread-index: Acbrl1xViV0FxTLDTTOAVZbqtkKZvAAFXySw
Thread-topic: [S] For loop
I second that...S-Plus is designed to work on chunks of data at a time -
for loops are usually unnecessary and are monster hogs on memory in
S-Plus. Avoid them as much as possible!

Win

-----Original Message-----
From: s-news-owner@lists.biostat.wustl.edu
[mailto:s-news-owner@lists.biostat.wustl.edu] On Behalf Of Petr Pikal
Sent: Monday, October 09, 2006 7:37 AM
To: Bikash Jain; s-news@lists.biostat.wustl.edu; s-news@wubios.wustl.edu
Subject: Re: [S] For loop

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

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


The information contained in this email message is intended only for the use of 
the individuals to whom it is addressed and may contain information that is 
privileged and sensitive. If the reader of this message is not the intended 
recipient, you are hereby notified that any dissemination, distribution or 
copying of this communication is strictly prohibited. If you have received this 
communication in error, please notify the sender immediately by email at the 
above referenced address. Thank you.

<Prev in Thread] Current Thread [Next in Thread>