1

I am new in R and I am stuck in a silly error.. Although I found some questions that tackle my problem I can't solve it.

ww <- waveMC_list[[5]]
sampling=44100
thresh=10

timer.output <- timer(ww, f=sampling, threshold=thresh,envt="abs",ksmooth=kernel("daniell",100))


i=0
min.length=0.05                    # minimum length of segment
segmts=length(timer.output[[4]])   # total amount of segments to evaluate
segments <- list()                 # output of valid segments
starts=timer.output[[4]]           # starting times
ends=timer.output[[5]]             # ending times



for(i in 1:segmts)
{
  if(i <= segmts)
  {
  while(starts[i] <= ends[i]) #print(TRUE)
    {
    if((ends[i]-starts[i])>min.length)
      {
       segments[[i]] <- env(WaveMC(cutw(ww, f=44100, from= starts[i], to=ends[i],plot=F), bit= 16, samp.rate=44100)
                            , f=44100, ksmooth=kernel("daniell",90),plot=F)
       print(paste('check', i, sep=' '))
       print(segmts)
          #env("ACAWAVEFILE", f=44100, ksmooth=kernel("daniell",90)) 
      }   
       i=i+1
    }
  }
}

Error in while (starts[i] <= ends[i]) { : 

missing value where TRUE/FALSE needed

Colm Prunty
  • 1,595
  • 1
  • 11
  • 29
marutonic
  • 21
  • 1
  • 1
  • 4

1 Answers1

2

The error means that the if condition evaluates to NA. This happens when either of the operands was NA. Check your input vectors for the values they contain.


Old reply, still relevant but results in a different error message:

The error means that your if condition is an empty vector. Why is it empty? Well, because of this part:

(ends[i]-starts[i])

Both ends and starts are a single element:

starts=timer.output[[4]]           # starting times
ends=timer.output[[5]]             # ending times

So of course ends[i] and starts[i] will only return an element for i==1 and an empty vector for any other value.

Konrad Rudolph
  • 530,221
  • 131
  • 937
  • 1,214