为什么有些函数不会忽略R中的空值? [英] Why some functions do not ignore null values in R?

查看:372
本文介绍了为什么有些函数不会忽略R中的空值?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个时间系列的日常回报。对于没有数据可用的观察结果,其值 NaN



尝试应用 PerformanceAnalytics 包中的StdDev 函数正确执行计算,并仅返回非空值的标准偏差。



尝试应用诸如平均值 min max ...返回错误的结果,即 NaN



可能是在 mean 函数中指定的东西?

解决方案

?mean
$ b


na.rm



一个逻辑值,指示在计算进行之前是否应该剥离NA值。

min max 也取一个n na.rm 参数。



最后,可能值得熟悉 >


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?

解决方案

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.

这篇关于为什么有些函数不会忽略R中的空值?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆