This is head of data G
Date Open Close Volume Adj.Close
2016-03-03 718.68 712.42 1958000 712.42
2016-03-04 714.99 710.89 1972100 710.89
2016-03-07 706.90 695.16 2985100 695.16
2016-03-08 688.59 693.97 2076300 693.97
2016-03-09 698.47 705.24 1421500 705.24
2016-03-10 708.12 712.82 2833500 712.82
and this is my function:
r <- c(1:(nrow(G)-1))
w <- c(1:(nrow(G)-2))
R <- function(j){
for(j in 1:((nrow(G)-1))) #calculating daily returns
{
r[j] <- (G[j+1,7]/G[j,7])
}
for(i in 10:((nrow(G)-1)))
{
w[i] <- (mean(r[(i-9):i])) #calculating moving average
}
return(w)
}
q <- vectorize(R)
curve(q)
This is the error I get
Error in xy.coords(x, y, xlabel, ylabel, log) :
(list) object cannot be coerced to type 'double'
I checked various posts, but nothing is helping. Thanks in advance.