Message Boards Message Boards

0
|
9806 Views
|
2 Replies
|
3 Total Likes
View groups...
Share
Share this post:

Replace values of nested list without resorting to part assignment?

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

2 Replies

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"]

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}}  *)
POSTED BY: Michael Rogers
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard

Group Abstract Group Abstract