Group Abstract Group Abstract

Message Boards Message Boards

0
|
13.7K Views
|
5 Replies
|
1 Total Like
View groups...
Share
Share this post:

[?] Dataset manipulation

Posted 11 years ago
POSTED BY: Martin Currie
5 Replies
Posted 9 years ago

Christopher, thank you for some very helpful advice! I am very excited about your approach to modifying the original dataset!

Edit:

Just to provide another option here is a solution that produces the same result as the recursive method you kindly posted.

MapAt[2 # &, Dataset[families], {"smith", "ratios", All,"height"}]
POSTED BY: Eric Laarz
Posted 9 years ago

First of all I'd like to thank Marco for his great answer to Martin's question. I am fairly new to Mathematica and really learned a lot from his examples.

Here's another suggestion, which (similar to Marco's third example) makes use of the Query function for datasets.

Dataset[families]["smith", "ratios", All, MapAt[2 # &, "height"]]

What's different is mainly the use of the operator form of the MapAt function. The advantage is improved readability and it retains the dataset structure consisting of a list of associations, which facilitates use of the output for further queries if so desired.

Cheers, Eric

POSTED BY: Eric Laarz

Your second option covers exactly what I need to do - thank you very much.

I wish it was easier to find advice like yours in the documentation...

POSTED BY: Martin Currie

Hi,

this could work:

Dataset[{2*#["height"], #["weight"]} & /@ families["smith", "ratios"]]

If you want to keep the dataset structure intact, this works:

Dataset[<|"height" -> 2*#["height"], "weight" -> #["weight"]|> & /@ families["smith", "ratios"]]

You can also use Query

Query[All, {2 #["height"] &, "weight"}]@Dataset[families["smith", "ratios"]]

Cheers,

Marco

POSTED BY: Marco Thiel
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard