问题
I have a time series of daily returns. Observations for which no data were available have value NaN
.
Trying to apply functions such as StdDev
from the PerformanceAnalytics
package the function correctly performs calculations and returns the standard deviation for only the not Null values.
Trying to apply functions such as mean
, min
, max
... return instead a wrong result, i.e. NaN
.
There is probably something to specify in the "mean
" function?
回答1:
From ?mean:
na.rm
a logical value indicating whether NA values should be stripped before the computation proceeds.
min
and max
also take an na.rm
argument.
Finally, it may be worth familiarizing yourself with ?na.omit.
来源:https://stackoverflow.com/questions/15617876/why-some-functions-do-not-ignore-null-values-in-r