Group Abstract Group Abstract

Message Boards Message Boards

1
|
1.2K Views
|
3 Replies
|
6 Total Likes
View groups...
Share
Share this post:

Adjust values in a dataset relative to their maximum

Posted 3 months ago
POSTED BY: Ehud Behar
3 Replies
Posted 3 months ago

I think you'll need to capture the max separately:

With[
 {max = ds[Max, "y"]},
 ds[All, {"y" -> (#/max &)}]]
POSTED BY: Eric Rimbey
Posted 3 months ago

In cases like this there is a choice between code elegance or computation efficiency. To paraphrase Hamlet: To save or not to save? There is no fixed answer.

POSTED BY: Hans Milton

Here is one way (but probably not the most elegant one):

ds[All, <|"x" -> #x, "y" -> #y - ds[Max, "y"]|> &]

My suspicion is that this not very effective, because this way ds[Max, "y"] seems to be evaluated again and again, as this does suggest so (using nn as a counter):

nn = 0;
ds[All, <|"x" -> #x, "y" -> #y - (nn++; ds[Max, "y"])|> &];
nn
(*   Out:  5   *)
POSTED BY: Henrik Schachner
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard