I am using Quantmode to extract a list of stock prices from Yahoo (Close price only), then write them into excel. I would like to get rid of "NA" values (resulting from non-trading days in certain country), and replace it with the prior value (the price of the day before).
> library(quantmod)
> x <- getSymbols("X", src ="yahoo", from=Sys.Date()-365, to=Sys.Date(), auto.assign=FALSE )
> x.close <- x[,4]
> y <- getSymbols("Y", src ="yahoo", from=Sys.Date()-365, to=Sys.Date(), auto.assign=FALSE )
> y.close <- y[,4]
> z <- getSymbols("Z", src ="yahoo", from=Sys.Date()-365, to=Sys.Date(), auto.assign=FALSE )
> z.close <- z[,4]
>ticker <- cbind(x.close, y.close, z.close)
>write.csv(as.data.frame(ticker), file="test.csv")
This would extract a lovely set of Close prices for stock items to an excel, however because it comes with "NA" values, it would disturb my functions when formatting in excel.
Could it really be possible for me to set something within R that could replace the NA after pulling the set from Yahoo?
Thank you in advance,