I'm really new to R and have been banging my head over this problem for two nights of browsing SO and other R resources... I have a data set where I have two matrices, one for stock market observations (stock returns) and one for weights (fraction of index market cap). In both cases columns are data for that stock ticker and rows are data for that month.
I wish to use density() to compare the rows (monthly returns) using Kullback Leibler divergence in a second step. My problem is that I cannot figure out a syntax to shift the weight row w[i,] used (since I have been using apply() / lapply(), this might be the problem) and then store the density() output matrices neatly in a list. My results simply end up being the first weight row rather than the whole.
I also tried using:
mylist <- list()
for (x in 1:n) {mylist <- density(R[x,]], 1, weights = (W[x,])}
which for some reason didn't output the probability / y-value output of density() ...
I would much appreciate any help!