On Monday, January 12, 2015 at 2:52:51 PM UTC-5, Douglas Bates wrote:
>
> This is trivial to write myself but I wanted to check that I am not
> missing an already-defined function. I need to scan an Int32 array
> replacing all instances of typemin(Int32), which is the missing value
> sentinel used by R, with zero(Int32). Is such substitution implemented by
> a function in Base?
>
You could do:
A[A .== typemin(Int32)] = zero(Int32)
If you really care about efficiency, it would be better to write your own
loop, as this allocates a temporary BitArray (for the .== result) and makes
two passes over the array.
I don't think there is a more specialized function for this operation.
(One of the nice things about Julia, though, is that you don't have to
obsessively pore over the manual to find a way to shoehorn every operation
into built-in functions; you can just write a loop. Coming from Matlab or
Python or R, one is instinctively reliant on the standard library for every
little thing because otherwise performance goes into the toilet, and it
takes a while to unlearn this instinct.)