Filter! vs filter

The error is telling you why: setindex! is not defined for UnitRange objects, that is you can’t change a single element in a UnitRange

The reason for this is that UnitRange is an efficient iterator, that doesn’t actually store all of the elements in the range, but just the starting point, end point, and step size. If you want to alter individual elements of your range, you should collect() your range into a vector.

5 Likes