Mathematica Asked on October 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.
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[{##}] &)
dataset /. Times -> (Row[{##}] &)
Answered by kglr on October 22, 2021
Get help from others!
Recent Questions
Recent Answers
© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP