Message Boards Message Boards

0
|
252 Views
|
1 Reply
|
1 Total Likes
View groups...
Share
Share this post:

How to modify column values relative to their maximum in a dataset?

Posted 12 days ago

I have the following dataset:

ds = Dataset@{
   <|"x" -> 1, "y" -> 45|>,
   <|"x" -> 2, "y" -> 19|>,
   <|"x" -> 3, "y" -> 20|>,
   <|"x" -> 4, "y" -> 47|>,
   <|"x" -> 5, "y" -> 30|>
   }

How can I create a new dataset the has the same "x" column but has a "y" column so that each entry in "y" is replaced by y_i - Max[#y], where Max[#y] is the maximum value of "y" in the dataset.

POSTED BY: Ehud Behar
Posted 12 days ago

Here's one way:

With[
 {maxY = ds[Max, "y"]},
 ds[All, {"x" -> Identity, "y" -> (# - maxY &)}]]
POSTED BY: Eric Rimbey
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