Replace -inf, NaN and NA values with zero in a dataset in R

后端 未结 4 589
深忆病人
深忆病人 2020-12-06 02:10

I am trying to run some trading strategies in R. I have downloaded some stock prices and calculated returns. The new return dataset has a number of -inf, NaN, and NA values.

4条回答
  •  执笔经年
    2020-12-06 02:40

    Using mutate_all in dplyr:

    library(dplyr)
    fortify.zoo(log_ret) %>% mutate_all(function(x) ifelse(is.infinite(x), 0, x))  
    

提交回复
热议问题