Is there a vectorised mechanism to return a vector of a different shape to the test object in R's ifelse(test, yes, no)
function?
The function is designed to return objects of the same shape as the test object:
> ifelse(TRUE, c(1, 3), 7)
[1] 1
But even if we get sneaky and try assigning objects so single length names are input, the result is the same:
> x <- c(1,3)
> ifelse(TRUE, x, 7)
[1] 1
The clunky control structure works:
> if(TRUE){c(1,3)}else{7}
[1] 1 3
But is there a vectorised way to achieve this?
[Edit: This is asking a different question to this one asking about inputting matrices, whereas this is asking about inputting vectors, even if the answer turns out to be similar. ]