TransWikia.com

Join string and quantities

Mathematica Asked by Las Des on August 22, 2021

How can I join a string and a quantity and still preserved the quantity format?
This what I have achieved:

dataset = Dataset[{
          <|"Column 1 of Quantities" -> 
         "Quantity number 1:" Quantity[10, "Meters"]|>,
       <|"Column 1 of Quantities" -> 
         "Quantity number 1:" Quantity[17, "Meters"]|>,
       <|"Column 1 of Quantities" -> 
         "Quantity number 1:" Quantity[16, "Meters"]|>,
       <|"Column 1 of Quantities" -> 
         "Quantity number 1:" Quantity[12, "Meters"]|>,
       <|"Column 1 of Quantities" -> 
         "Quantity number 1:" Quantity[22, "Meters"]|>,
       <|"Column 1 of Quantities" -> 
         "Quantity number 1:" Quantity[2, "Meters"]|>}]

Beacuse what I get is the string, but with the quantity in parenthesis.

One Answer

Use Row[{"Quantity number 1:", Quantity[10, "Meters"]}] or StringRiffle[{"Quantity number 1:", Quantity[10, "Meters"]}] instead of Quantity number 1:" Quantity[10, "Meters"] when you define dataset. (Similarly, for other entries.)

If dataset is already define as in OP, you can use ReplaceAll to replace Times with Row or with StringRiffle as follows:

dataset /. Times -> (StringRiffle[{##}] &)

enter image description here

dataset /. Times -> (Row[{##}] &)

enter image description here

Correct answer by kglr on August 22, 2021

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP