Error in "while ( grep(m, matchidx) <= 10 ) {}" .... "condition has length > 1"

Viewed 17

m is an integer from a range list... a surrounding "for ( m in matchidx ) {}" loop with matchidx is an array of integers:

  labmatchidx = grep( Headerstr, LabMatches)  # list of indices of lab matches
  
  #  labmatchidx
  #   [1]   1   2  14  39  67  84  89 100 115 131 145 166 181 222 236 269

  nlabs = length(labmatchidx)
  lablist = vector(mode = "list", 2*nlabs)  # one line for Collected - date

  labnbr = 0
  
  for (m in labmatchidx) {  # for lab match "m"
    
    while ( grep( m, labmatchidx ) <= 10 ) { # just get the first 10 labs

When I try to create a minimal test case at the command line, it works (and you get a working infinite loop)

xint = labmatchidx
while ( grep(39, xint) <= 10 ) { cat("ok\t") }

But for this:

> labmatchidx
 [1]   1   2  14  39  67  84  89 100 115 131 145 166 181 222 236 269
> for (m in labmatchidx) { while ( grep(m, labmatchidx)<= 10) {cat("ok\n")}} 
Error in while (grep(m, labmatchidx) <= 10) { : 
  the condition has length > 1
0 Answers
Related