When using the code, I noticed that ifelse is used. This function also exists in R, and for me one of the main reasons I try to avoid R. In R, it's just a hack to get stuff done because the language isn't very expressive, and because everything has to be vectorized. Luckily, we're using Julia here, so we can use clearer syntax! :smile:
In this PR, I propose to change all occurrences of ifelse with list comprehensions.
Example
Say, we want to replace "a" with 1, and "b" with 2 in A:
julia> A = ["a", "b", "a"]
3-element Array{String,1}:
"a"
"b"
"a"
When using the code, I noticed that
ifelse
is used. This function also exists in R, and for me one of the main reasons I try to avoid R. In R, it's just a hack to get stuff done because the language isn't very expressive, and because everything has to be vectorized. Luckily, we're using Julia here, so we can use clearer syntax! :smile:In this PR, I propose to change all occurrences of
ifelse
with list comprehensions.Example
Say, we want to replace
"a"
with 1, and"b"
with 2 inA
:We could write
However, it is more common (and, I think, more readable) to use a ternary expression (like in C) in combination with a list comprehension