Error in "If" statement in R coding -


this code:

#start of code# test1<-function(c,x){ high=0 low=0 samp=null  samp=sample(c,x) for(i in 1:x){ if(samp[i]>1){high=high+1} else if (samp[i]<0){low=low+1}} c(high,low,mean(samp),var(samp),samp) }  sim1 <-function(c,x){ replicate(nsim,{test1(c,x)})}  size=10 a<-sim1(overall,size)  listnormwor=null countnormwor=0 meannormwor=null  for(i in 0:nsim-1){ **if (a[1+(size+4)*i]+a[2+(size+4)*i]==0)**{  countnormwor=countnormwor +1 (z in 5:(size+4)){  listnormwor=c(listnormwor, a[z+(size+4)*i])} meannormwor=c(meannormwor,a[3+(size+4)*i])} }  countnormwor mean(meannormwor) var(listnormwor) 

simply, want if there no outliers (indicated '0' in first , second value of every 14 data points), count normal bucket , keep values calculate variance , mean later.

but problem that, generates values , @ end, provides actual values want.

for example, must satisfy length(listnormwor) = 10 * countnormwor

but gives me ridiculous amount of data , when play around if statement, says "missing value true/false needed."

i'd suggest stepping through code (sending each line interpreter) 1 line @ time. inspect value of variables calling them in interpreter. bet lead source of problem. start, create values x , c inside function work there. instead of running for loop, create own index variable i. again, point work line line , check expectations against values variables take @ each point.


Comments

Popular posts from this blog

jquery - How do you format the date used in the popover widget title of FullCalendar? -

asp.net mvc - SSO between MVCForum and Umbraco7 -

Python Tkinter keyboard using bind -