R:产生的 NaN [英] R: NaNs produced

查看:67
本文介绍了R:产生的 NaN的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在 R Studio 中有一个时间序列.现在我想计算这个系列的 log().我尝试了以下方法:

I have a time series in R Studio. Now I want to calculate the log() of this series. I tried the following:

i <- (x-y) 
ii <- log(i)

但后来我得到以下信息:警告消息:在日志(i)中:产生的 NaN 为了检查这个,我使用了:table(is.nan(ii)),它给了我以下输出:

But then I get the following: Warning message: In log(i): NaNs produced To inspect this I used: table(is.nan(ii)) which gives me the following output:

FALSE  TRUE 
 2480     1 

所以我假设现在我的时间序列中有 1 个 NaN.我的问题是:我可以使用什么代码,R 向我展示了 NaN 产生的观察结果?这是一个小数据样本:i <- c(9,8,4,5,7,1,6,-1,8,4)顺便说一句,我如何在 stackoverflow 中输入数学公式,例如 log(x)?非常感谢

So I assume, that there is 1 NaN in my time series now. My question is: what code can I use, that R shows me for which observation a NaN was produced? Here is a small data sample: i <- c(9,8,4,5,7,1,6,-1,8,4) Btw how do I type mathematical formulas in stackoverflow, for example for log(x)? Many thanks

推荐答案

正如我在评论中所说,要知道哪个观察生成了 NaN,您可以使用函数 which:

As I said in my comment, to know which observation generated the NaN, you can use function which:

i <- c(9,8,4,5,7,1,6,-1,8,4)
which(is.nan(log(i))) # 8

这篇关于R:产生的 NaN的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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