Assigning value to Matrix in R -



Assigning value to Matrix in R -

i have loaded info set using read.csv. contains headers in first row , bunch of stock prices in different columns.

i trying perform rolling analysis (mean, sd or other simple statistical function , assign an element in matrix have defined)

however maintain getting na cells when writing csv

my code

{ apd = read.table(file="c:\\path\\pasted info temp.csv",head=true,sep=",",blank.lines.skip = true,row.names = null); dma = matrix(nrow=dim(apd)[1]+25,ncol=dim(apd)[2]+25) = ncol(apd); dmano = 20; for(i in 3:a) { z = length(apd[1]) for(j in dmano:z) { dma[[i][j]] <- mean(apd$abnl[j-dmano+2:j]) } } }

as agstudy suggested rollapply best option, since extremely faster.

as code: need brackets in (j-dmano+2):j , in r 1 subsets matrix in different manner, namely i-th column , j-th row of dma accesed via dma[j,i]. data.frame$x[] produces redundant subseting. seek one:

for(i in 3:a) { z = length(apd[1]) for(j in dmano:z) { dma[j,i] <- mean(apd[(j-dmano+2):j,"abnl"]) } } }

r matrix assign

Comments

Popular posts from this blog

php - Android app custom user registration and login with cookie using facebook sdk -

django - Access session in user model .save() -

php - .htaccess Multiple Rewrite Rules / Prioritizing -