Ozgur -- No, this is not what the OP seems to be asking for (and it's
bad code anyways -- I've mentioned the importance of pre-allocation to
you before):
OP, if I understand you, you are looking for a cumsum() operation:
something like:
t <- rbinom(1000, 1, 0.5)
t[t==0] <- (-1)
cumsum(t)
Alterna
Hi,
Your mistake seems to be in
sum(v[1:x])
You create "x" as a vector but your treat it as a single number.
v[1:x] expects "x" to be a single number and only considers its first
element which is 1.
If I understand your query correctly, the following might handle your
problem:
sum.vec <-NU
2 matches
Mail list logo