Quantcast
Channel: Active questions tagged r - Stack Overflow
Viewing all articles
Browse latest Browse all 201894

Why is my matrix being filled with NAs, not the output of the loop?

$
0
0

I am looking to fill matrix tab with the output of the look (variable ma), however instead it is filling the matrix with NAs


MA<-data.matrix(my_data)
MA2=MA[-247,-8]
tab<-matrix(ncol=2,nrow=253)
ma4<-matrix(ncol=1,nrow=253)
tab[,1]<-MA2[,1]
for (n in 1:248) {
  y<-MA2[c(n,n+1,n+2,n+3,n+4,n+5),5]
  z<-sum(y)
  mav<-z/5
  tab[[n,2]]<-mav
  n<-n+1
}

link to data is here https://uk.finance.yahoo.com/quote/LLOY.L/history?p=LLOY.L


Viewing all articles
Browse latest Browse all 201894

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>