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
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
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
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
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
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
6 matches
Mail list logo