Skip to content
Prev 105908 / 398506 Next

Switch and integer

If the value of EXPR is an integer between 1 and nargs()-1 then the
corresponding element of ... is evaluated and the result returned.

So, for integers you don't give names to the elements in ...  This should work:

test=c(3,9,3,9,3,9,8,9,8,9,8,9,3,9,3,9,5,9,3,9,1,2,7,9,3,9,1,1,2,2,3,9,2,1,2,5,9,8,9,1,2)
count1 <- 0
for (i in 1:length(test))
 switch(EXPR=test[i],
     NULL,
     NULL,
     NULL,
     count1 <- count1 +1,
     count1 <- count1 +1,
     count1 <- count1 +1,
     count1 <- count1 +1,
     count1 <- count1 +1,
     NULL
     )
 count1
On 11/12/06, Knut Krueger <Knut-krueger at einthal.de> wrote: