Re: [R] Warning message: numerical expression has 1000 elements: only the first used

2012-05-30 Thread R. Michael Weylandt
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

Re: [R] Warning message: numerical expression has 1000 elements: only the first used

2012-05-30 Thread Özgür Asar
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