Revision dcca1c2f-492b-4bc9-a28b-010e789d86a8 - Code Golf Stack Exchange

# [R], <s>31</s> 29 bytes

<!-- language-all: lang-r -->

 function(a,b)pmax(a,b)+a*!a-b

`pmax` takes the parallel maximum of the two (or more) arrays (recycling the shorter as needed).

I was looking at [Luis Mendo's comment](https://codegolf.stackexchange.com/questions/140748/get-the-best-of-two-arrays#comment344950_140758) and obviously I realized the approach could work for R as well. That got me to 30 bytes, but then I started playing around with different ways of getting indices instead to improve my original answer, and stumbled upon `!a-b` as `TRUE` where `a==b` and `FALSE` otherwise, equivalent to `a==b`. However, for whatever reason, R doesn't require parentheses around `!a-b` as it does for `a==b`, which saved me two bytes.

[Try it online! (new version)](https://tio.run/##K/qfZvs/rTQvuSQzP08jUSdJsyA3sQLM0E7UUkzUTfqfppFXmptalJmsYaCpg2BqcqVpJGsY6hjpGGvqgBjGOkZwQQVjINIz0lEw0gPLArmGcBEzTc3/AA "R – Try It Online")

[Try it online! (original)][TIO-j6w6eya4]

[R]: https://www.r-project.org/
[TIO-j6w6eya4]: https://tio.run/##RYlBCoAgEEX3ncLlTA2SCu08zCgJLrSQhG5v5cLgL95/r7RgW6jZX/HIwOTwTHx3WHgGttZhC5Br2kv0sCL9iFMAD4o0GaQPDOkhhXknNQkte32vGmZDbA8 "R – Try It Online"

AltStyle によって変換されたページ (->オリジナル) /