R: NaNs produced

前端 未结 2 897
后悔当初
后悔当初 2021-01-22 15:08

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)

But

2条回答
  •  南方客
    南方客 (楼主)
    2021-01-22 15:32

    Use the test to subset your original vector with the values that produce NaN:

    > i <- c(9,8,4,5,-7,1,6,-1,8,4,Inf,-Inf,NA)
    > i[which(is.nan(log(i)))]
    [1]   -7   -1 -Inf
    Warning message:
    In log(i) : NaNs produced
    

    Here you see that -7, -1, and -Inf produced NaN.

    Note that log(NA) is not NaN, its NA, which is a different sort of not-numberness.

提交回复
热议问题