I am having trouble with the below switch statement:
names <- rep(1:num.bins, 3)
names <- sort(names)
c.names <- sapply(1:(3*num.bins), function(i){
switch( i %% 3,
1 = paste0("M", names[i]),
2 = paste0("F", names[i]),
0 = paste0("E", names[i])
)
})
If my 'num.bins' is 3, I'd like the following output:
print(names)
[1] 1 1 1 2 2 2 3 3 3
print(c.names)
[1] "M1" "F1" "E1" "M2" "F2" "E2" "M3" "F3" "E3"
however, I'm getting an error. Thank you very much for your help.