Re: [R] How to eliminate this for loop ?

2010-11-09 Thread Nick Sabbe
- From: David Winsemius [mailto:dwinsem...@comcast.net] Sent: maandag 8 november 2010 15:04 To: Nick Sabbe Cc: 'PLucas'; r-help@r-project.org Subject: Re: [R] How to eliminate this for loop ? On Nov 8, 2010, at 4:30 AM, Nick Sabbe wrote: Whenever you use a recursion (that cannot be expressed

Re: [R] How to eliminate this for loop ?

2010-11-09 Thread Greg Snow
[mailto:r-help-boun...@r- project.org] On Behalf Of Greg Snow Sent: Monday, November 08, 2010 1:15 PM To: PLucas; r-help@r-project.org Subject: Re: [R] How to eliminate this for loop ? If you are willing to shift the c vector by 1 and have 1 (the initial value) as the start of c, then you can

Re: [R] How to eliminate this for loop ?

2010-11-09 Thread Bert Gunter
Erich: (Assuming this is correct), this is very nice. However, I just wanted to point out that if you look at the code for Reduce, you'll find it's implemented with for loops. So the OP's original version using a for loop is likely to be faster (just as it's likely to be faster than my actual

Re: [R] How to eliminate this for loop ?

2010-11-09 Thread William Dunlap
...@r-project.org [mailto:r-help-boun...@r- project.org] On Behalf Of Greg Snow Sent: Monday, November 08, 2010 1:15 PM To: PLucas; r-help@r-project.org Subject: Re: [R] How to eliminate this for loop ? If you are willing to shift the c vector by 1 and have 1 (the initial value

Re: [R] How to eliminate this for loop ?

2010-11-09 Thread Greg Snow
- From: r-help-boun...@r-project.org [mailto:r-help-boun...@r- project.org] On Behalf Of William Dunlap Sent: Tuesday, November 09, 2010 10:07 AM To: PLucas; r-help@r-project.org Subject: Re: [R] How to eliminate this for loop ? Note that for long vectors the OP's code would go much

[R] How to eliminate this for loop ?

2010-11-08 Thread PLucas
Hi, I would like to create a list recursively and eliminate my for loop : a-c() a[1] - 1; # initial value for(i in 2:N) { a[i]-a[i-1]*b - c[i-1] # b is a value, c is another vector } Is it possible ? Thanks -- View this message in context:

Re: [R] How to eliminate this for loop ?

2010-11-08 Thread Nick Sabbe
] How to eliminate this for loop ? Hi, I would like to create a list recursively and eliminate my for loop : a-c() a[1] - 1; # initial value for(i in 2:N) { a[i]-a[i-1]*b - c[i-1] # b is a value, c is another vector } Is it possible ? Thanks -- View this message in context: http://r

Re: [R] How to eliminate this for loop ?

2010-11-08 Thread Dennis Murphy
Hi: ?Recall HTH, Dennis On Mon, Nov 8, 2010 at 1:25 AM, PLucas plucasplucasplu...@yopmail.comwrote: Hi, I would like to create a list recursively and eliminate my for loop : a-c() a[1] - 1; # initial value for(i in 2:N) { a[i]-a[i-1]*b - c[i-1] # b is a value, c is another vector

Re: [R] How to eliminate this for loop ?

2010-11-08 Thread David Winsemius
653, 9000 Gent ring: 09/264.59.36 -- Do Not Disapprove -Original Message- From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org ] On Behalf Of PLucas Sent: maandag 8 november 2010 10:26 To: r-help@r-project.org Subject: [R] How to eliminate this for loop ? Hi, I

Re: [R] How to eliminate this for loop ?

2010-11-08 Thread Bert Gunter
- From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On Behalf Of PLucas Sent: maandag 8 november 2010 10:26 To: r-help@r-project.org Subject: [R] How to eliminate this for loop ? Hi, I would like to create a list recursively and eliminate my for loop : a-c() a[1

Re: [R] How to eliminate this for loop ?

2010-11-08 Thread Greg Snow
-Original Message- From: r-help-boun...@r-project.org [mailto:r-help-boun...@r- project.org] On Behalf Of PLucas Sent: Monday, November 08, 2010 2:26 AM To: r-help@r-project.org Subject: [R] How to eliminate this for loop ? Hi, I would like to create a list recursively

Re: [R] How to eliminate this for loop ?

2010-11-08 Thread Erich Neuwirth
Reduce(function(x1,x2)b*x1-x2,c,init=1,accum=TRUE) might be what you are looking for. This is not fully tested, so you should test it before you want to use it. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do