I’m looking for something like cond ? a : b or if(cond, a, b) in R (cond is some condition, returning vector of TRUE/FALSE). I know that in many cases I can use trick with the assignment:
tmp[cond] <- a
but this is not good for me as I don’t want to change anything – I just need to get immediate R-value in expression. Thanks!
will do the trick if
aandbare single values or both have the same length ascond. Otherwise, you havewhere
condmust have length 1 andaandbcan have any length.