r - Replacement has more rows than data in for loop -
First of all, I know that there is a question with a similar title, but it does not solve my problem.
I'm just trying to create a logarithmic stock price index with a log base 10 with loop like this:
t < - nrow [dat] dat $ logind & lt; - Matrix (NA, T, 1) Log in for $ 1 $ [1] & lt; - 100 (i in 2: t) {dat $ logind [i] & lt; - ($ $ logind [i-1] * (1 + dat $ logr [i]))}
I have read that The error can be solved by using another method to select columns such as dat
is dataframe, logged in
There is only one column that I have created, grab the index, and there are logarithmic returns in logger, however, it throws me down:
`$ & Lt; -. Data Error in frame` (`* TMP * ',' log '', value = C (100, 99.3891882,: 1155 rows in substitution, 1154 in data)
dat [, column]
, but how to
Instead of code> t <- nrow (dat) t <- nrow [dat] code> T
because you are overtricating the function t
(matrix / vector transfer).
For Loop using R-rated operators, such as:
$ longind - c (100, $ $ logind [1: (nrow (dat ) -1)] * (1 + $ $ $ logr [-1]))
Comments
Post a Comment