For example, if I want a list of $\phi(n)$ for $1 \leq n \leq 100$ but if $n$ is a multiple of 3 I want to show a 3 instead of $\phi(n)$. I tried
ReplacePart[EulerPhi[Range[100]], Table[{3n}, {n, 33}] -> 3]
but this just feels wrong.
Or a somewhat more involved example: show $4n$ except when $n \equiv 1 \pmod 4$, in which case show just $n$.
I am aware both of these can be accomplished with If
. But there's a better way, isn't there?
expr = Range[20]; expr[[3 ;; ;; 3]] = 3;expr
$\endgroup$expr = 4 Range[20]; expr[[Range[1, 20, 4]]] = Range[1, 20, 4]; expr
:))) $\endgroup$