Very simple question. I have a list, "lRet", of 29 vectors containing returns from the DJ index. each of the 29 stocks are observed 270 times (every day one year)
I have a matrix "DescStat" carrying 7 different descriptive statistics.
I wish to fill my matrix with for instance the mean.
DescStat <- matrix(0,29,7)
rownames(DescStat) <- mTicker$Symbol
colnames(DescStat) <- c("mean", "median", "variance", "kurtosis", "skewness", "rho", "rho2")
> head(DescStat)
mean median variance kurtosis skewness rho rho2
TRV 0 0 0 0 0 0 0
XOM 0 0 0 0 0 0 0
V 0 0 0 0 0 0 0
PFE 0 0 0 0 0 0 0
CAT 0 0 0 0 0 0 0
IBM 0 0 0 0 0 0 0
But when I use the command my matrix looks weird when I look at it again:
DescStat[,1] <- lapply(lRet, mean)
head(DescStat)
> DescStat[,1] <- lapply(lRet, mean)
> head(DescStat)
[[1]]
[1] 0.03633877
[[2]]
[1] -0.02521246
[[3]]
[1] 0.09549176
[[4]]
[1] 0.01092361
I also tried
DescStat[,1] <- apply(lRet, 2, mean)
but I get an error dim(X) must have a positive length.
What am I doing so wrong?