我试图在R中运行一些交易策略.我已经下载了一些股票价格和计算回报.新的返回数据集具有多个-inf,NaN和NA值.我正在复制一行数据集(log_ret).它是一个动物园数据集.
library(zoo)
log_ret <- structure(
c(0.234,-0.012,-Inf,NaN,0.454,Inf), .Dim = c(1L, 6L),
.Dimnames = list(NULL, c("x", "y", "z", "s", "p", "t")),
index = structure(12784, class = "Date"),
class = "zoo"
)
x y z s p t
2005-01-01 0.234 -0.012 -Inf NaN 0.454 Inf
Run Code Online (Sandbox Code Playgroud)
如何用0替换这些不需要的值?