1

I am aware of How would I use Map on a Dataset column? still I cannot see how I should use MovingMap on a Dataset.

Even the identity functions does not work!

MovingMap[# &, dataset[[All, "Eons"]], 1]

My dataset is constructed like this

eons = {
  {{2021, 02, 22}, 95},
  {{2021, 02, 23}, 96},
  {{2021, 02, 24}, 100},
  {{2021, 02, 25}, 105}}
dataset = 
 Dataset[Map[Association[{"Date" -> #[[1]], "Eons" -> #[[2]]}] &, 
   eons]]

I can do things that are mere application of fuctions to a single row, e.g. Map[<|#, "Sqrt" -> Sqrt[#Eons]|> &, dataset ]. However using

MovingMap[# &, dataset[All, "Eons"], 1]

as suggested returns itself as output, which usually means mathematica does not know what to do.

Rho Phi
  • 1,420
  • 11
  • 21
  • I believe you want MovingMap[# &, dataset[All, "Eons"], 1] - note the single brackets. You will need to give an example of your dataset for more help though :) – Carl Lange May 14 '21 at 08:16
  • Thanks for the susggestion, this too gives the same trouble as using Part or [[, mathematica return the input as output ... meaning it did not understand – Rho Phi May 14 '21 at 08:31
  • 3
    Indeed, it looks like MovingMap doesn't like to work directly on Dataset in this way. You can do either MovingMap[# &, Normal@dataset[All, "Eons"], 1] or dataset[MovingMap[(# &), #, 1] &, "Eons"]. – Carl Lange May 14 '21 at 08:43
  • From the help of MovingMap: "The data can be a list of values {Subscript[x, 1],Subscript[x, 2],[Ellipsis]}, a list of time-value pairs {{Subscript[t, 1],Subscript[x, 1]},{Subscript[t, 2],Subscript[x, 2]},[Ellipsis]}, a TimeSeries, EventSeries, or TemporalData.", but not Dataset. – Daniel Huber May 14 '21 at 15:31

1 Answers1

4

As I posted in my comment: it looks like MovingMap doesn't like to work directly on Dataset in this way.

There are a few alternatives.

You can use the Dataset-style syntax to apply a function to a column's values:

dataset[MovingMap[(# &), #, 1] &, "Eons"]

You can do

MovingMap[# &, Normal@dataset[All, "Eons"], 1]

in order to convert the dataset's values into a simple list using Normal.

You can also convert your Dataset into TimeSeries data that MovingMap can operate directly on:

dataset = 
 Dataset[Map[
   Association[{"Date" -> DateObject@#[[1]], "Eons" -> #[[2]]}] &, 
   eons]]
ts = TimeSeries@Normal@Values@dataset
MovingMap[# &, ts, 1] (* returns a TimeSeries as well *)
Carl Lange
  • 13,065
  • 1
  • 36
  • 70