David Barron schrieb:
>
> If the value of EXPR is an integer between 1 and nargs()-1 then the
> corresponding element of ... is evaluated and the result returned.
>
Thank you, I wondered about the
> integer between 1 and nargs()-1
and the example from the help file for(i in c(-1:3,9)) print(switch
Knut Krueger einthal.de> writes:
>
> Switch is working with character , with integer, but not in the third
> example
...
> # not working
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 (
>From the help entry for switch:
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
I searched the help list and the manual, but I do not find my mistake.
Switch is working with character , with integer, but not in the third
example
Regards Knut
count1 <- 0
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",