I have a Dataset
in the following form but with many more rows and a few other columns.
SeedRandom[123];
ds =
Dataset[
AssociationThread[{"Date", "R1","R2"},
{DatePlus[DateObject@{2007, 12, 31}, {#, "EndOfMonth"}],
Sequence @@ RandomReal[{-0.5, 1}, 2]}
] & /@ Range[3]
]
I would like to apply Rest@FoldList[#1 (1 + #2/100) &, 100, #] &
to columns "R1"
and "R2"
to get the following.
Currently I am destroying the dataset and then recreating it to get this result.
Dataset@MapThread[Append,
{<|"Date" -> DatePlus[DateObject@{2007, 12, 31}, {#, "EndOfMonth"}]|> & /@ Range[3],
Normal@ds[Rest@FoldList[#1 (1 + #2/100) &, 100, #] &, {"R1", "R2"}]}]
However, I would like not to have to do this because the columns that do not need to be folded need to be reincorporated into the result (e.g."Date"
in the example). The ds[All, {"R1" -> f, "R2" -> f}]
syntax operates on each column's row values individually. Is there some similar syntax for folding a column? Or a non destructive way of doing this?
Ideally I am looking to get the following but I can prepend the starting 100 value and date to the dataset if I can get the above.