Re: [R] Scope and sapply

2010-06-13 Thread Berend Hasselman
Worik R wrote: ... N - 10 ## x simulate a return series x - runif(N)-.5 ## Build an array of cumulative returns of a portfolio starting with $1 as it changes over time y - rep(0, length(x)) y[1] - 1+1*x[1] for(i in 2:N){ y[i] - y[i-1]+y[i-1]*x[i] } ## y is that return

Re: [R] Scope and sapply

2010-06-13 Thread Gabor Grothendieck
On Sat, Jun 12, 2010 at 11:40 PM, Worik R wor...@gmail.com wrote: I was careless. Here is a better example of what I am trying to.  With the '-' you offered. ?- That was exactly what I needed, thankyou. Just as an aside I am assuming these are just examples to illustrate scope. In

[R] Scope and sapply

2010-06-12 Thread Worik R
I am puzzled by the scope rules that apply with sapply. If I want to modify a vector with sapply I tried... N - 10 vec - vector(mode=numeric, length=N) test - function(i){ vec[i] - i } sapply(1:N, test) vec but it not work. How can this be done? Worik [[alternative HTML version

Re: [R] Scope and sapply

2010-06-12 Thread Sarah Goslee
Hi, On Sat, Jun 12, 2010 at 9:22 PM, Worik R wor...@gmail.com wrote: I am puzzled by the scope rules that apply with sapply. If I want to modify a vector with sapply I tried... N - 10 vec - vector(mode=numeric, length=N) test - function(i){  vec[i] - i } sapply(1:N, test) vec You

Re: [R] Scope and sapply

2010-06-12 Thread Gabor Grothendieck
On Sat, Jun 12, 2010 at 9:22 PM, Worik R wor...@gmail.com wrote: I am puzzled by the scope rules that apply with sapply. If I want to modify a vector with sapply I tried... N - 10 vec - vector(mode=numeric, length=N) test - function(i){  vec[i] - i } sapply(1:N, test) vec but it not

Re: [R] Scope and sapply

2010-06-12 Thread Worik R
I was careless. Here is a better example of what I am trying to. With the '-' you offered. ?- That was exactly what I needed, thankyou. cheers Worik N - 10 ## x simulate a return series x - runif(N)-.5 ## Build an array of cumulative returns of a portfolio starting with $1 as it changes