I am randomly generating elements of a vector which can be NaN. In the end, when I sum all elements of the vector, it returns NaN.

How can I exclude NaN from the vector so that the sum is not NaN?

Here is the issue:

> f <- c(0.0152, 0.023, 0.0907, 0.0082, 0.0121, 0.0819, 0.0218, 0.0386, NaN, 0.0073, 1e-04, 0.009, 0.0447, 0.0429, 0.0085)

> sum(f)[1] NaN