Reputation: 4444
Can someone explain me why the code line below :
Returns <- eapply(Data,function(s) ROC(Ad(s), type="discrete"))
does return :
I guess that it's classed by value but quite not sure
Since Data
is built as below :
Why isn't my list structured as excepted :
Returns :
-> ACA.PA
-> BNP.PA
-> UG.PA
How would I Fix this in order to keep the same structure ?
Reproducible Example
stock_list <- c("ACA.PA","BNP.PA","UG.PA")
Data <- new.env(hash = FALSE)
getSymbols(stock_list,
from = start_date,
to = end_date,
src = "yahoo",
periodicity = "monthly",
env=Data)
Returns <- lapply(Data,function(s) ROC(Ad(s), type="discrete"))
Upvotes: 1
Views: 42
Reputation: 887971
if we need the output in the same order, we can use mget
with envir
specified as 'Data'
Returns <- lapply(mget(stock_list, envir = Data),
function(s) ROC(Ad(s), type="discrete"))
names(Returns)
#[1] "ACA.PA" "BNP.PA" "UG.PA"
According to ?eapply
order of the components is arbitrary for hashed environments.
and in ?new.env
env.profile returns a list with the following components: size the number of chains that can be stored in the hash table, nchains the number of non-empty chains in the table (as reported by HASHPRI), and counts an integer vector giving the length of each chain (zero for empty chains). This function is intended to assess the performance of hashed environments. When env is a non-hashed environment, NULL is returned.
Upvotes: 1