ttfreitas
(Thadeu Freitas Filho)
June 25, 2018, 2:06am
1
I have a nested list of financial data such as:
test={{{2000,1,4},-5.93336},{{2000,1,5},1.09736},{{2000,1,6},7.19}}
I would like to replace [[All,2]] with
Log[1+[[All,2]]/100]
using ReplacePart instead of part assignment , such as
test[[All, 2]] = Log[1 + (test[[All, 2]])/100]
How can I accomplish that?
Thank you
mroge02
(Michael Rogers)
June 25, 2018, 3:32am
2
Not what you requested, but the same effect:
Thread[{test[[All, 1]], Log[1 + test[[All, 2]]/100]}]
(* {{{2000, 1, 4}, -0.0611667}, {{2000, 1, 5}, 0.0109138}, {{2000, 1, 6}, 0.0694328}} *)
mitch
(Mitch Stonehocker)
June 25, 2018, 5:48am
3
If I’m not certain what your end goal is or what the values are, but with a few assumptions on my part perhaps the following is helpful. Starting with you test list, I make a dataset
testDS[S1] = <| DateObject[#[[1]]] -> <|"value" -> #[[2]]|> & /@ test|> // Dataset
where the dates are keys. Then I create a column of logs (if I’m following your request correctly)
testDS[S2] = testDS[S1][All, "value" /* Replace[value_ :> <|"value" -> value, "log" -> (Log[1 + value/100])|>]]
Now you can operate on testDS[S2] as you wish. For instance, get all the log values with their date keys
testDS[S2][All, "log"]