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

Özgür Asar oasar at metu.edu.tr
Thu May 31 08:08:42 CEST 2012


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 <-NULL
for (x in 1:1000){
t <- rbinom(1000, 1, 0.5)
v <- replace(t,t==0,-1)
sum.vec<-c(sum.vec,sum(v[1:x]))
}

Best
Ozgur 

-----
************************************
Ozgur ASAR

Research Assistant
Middle East Technical University
Department of Statistics
06531, Ankara Turkey
Ph: 90-312-2105309
http://www.stat.metu.edu.tr/people/assistants/ozgur/
--
View this message in context: http://r.789695.n4.nabble.com/Warning-message-numerical-expression-has-1000-elements-only-the-first-used-tp4631813p4631903.html
Sent from the R help mailing list archive at Nabble.com.



More information about the R-help mailing list