If I generate a vector of values, some of which are negative:
d <- rnorm(1000, 4, 10)
z <- sapply(d, function(x) x^1.2)
z
will contain a mix of real values and NaN
s. Any values that were originally negative in the vector will be NaN
.
Why is this? How can I fix it?
You should use complex
numbers, like below
(d + 0i)^1.2