Density Value for each Return
问题 I have a dataframe "foo" looking like this Date Return 1998-01-01 0.02 1998-01-02 0.04 1998-01-03 -0.02 1998-01-04 -0.01 1998-01-05 0.02 ... 1998-02-01 0.1 1998-02-02 -0.2 1998-02-03 -0.1 etc. I would like to add to this dataframe a new column showing me the density value of the corresponding return. I tried: foo$density <- for(i in 1:length(foo$Return)) density(foo$Return, from = foo$Return[i], to = foo$Return[i], n = 1)$y But it didn't work. I really have difficulty applying a "function" to