0
$\begingroup$

enter image description here

As you can see from the picture, how can I change all the "->" symbols to "-"?

$\endgroup$

2 Answers 2

3
$\begingroup$

Look at the FullForm of a Rule

a -> b // FullForm

(* Rule[a, b] *)

SeedRandom[1234];

b3 = Thread[{a, b, c, d, e} -> RandomInteger[100, 5]]

(* {a -> 8, b -> 72, c -> 44, d -> 38, e -> 22} *)

b3 /. Rule[a_, b_] :> StringForm["``-``", a, b]

enter image description here

or with some space

b3 /. Rule[a_, b_] :> StringForm["``\[ThinSpace]-\[ThinSpace]``", a, b]  

enter image description here

$\endgroup$
5
  • $\begingroup$ Thanks for your answer, Mr Hanlon, I completely got the "-" symbol, but I faced another trouble. How can I transform the output into dataset? I tried to use Dataset function, but it showed lots of symbols different from the output. $\endgroup$ Mar 22, 2021 at 7:24
  • $\begingroup$ b3 = Thread[{a, b, c, d, e} -> RandomInteger[100, 5]]; Dataset[Association[b3]] $\endgroup$
    – Bob Hanlon
    Mar 22, 2021 at 7:30
  • $\begingroup$ Oh! I just got the same anser with Dataset function, there are lots of mess symbols. $\endgroup$ Mar 22, 2021 at 7:46
  • $\begingroup$ Post a question showing data (for a small sample) and your code. Note that you cannot be be using the transformation of the Rule shown above since the rules must remain to form the association. $\endgroup$
    – Bob Hanlon
    Mar 22, 2021 at 7:50
  • $\begingroup$ For example: c1 = {x, y, z};c2 = {1, 2, 3};c3 = Thread[c1 -> c2] I want to get the dataset of c3, and when I just use Dataset function, it shows "->" symbol, I want to replace it with symbol "-". $\endgroup$ Mar 22, 2021 at 8:25
3
$\begingroup$

a->b is a shortcut for Rule[a,b]. Therefore, what you have to do is to replace Ruleby Subtract. E.g.:

SeedRandom[1]
list = Thread[{a, b, c, d, e} -> RandomInteger[100, 5]]

(* {a -> 80, b -> 14, c -> 0, d -> 67, e -> 3} *)

list /. Rule -> Subtract

(*  {-80 + a, -14 + b, c, -67 + d, -3 + e}  *)
$\endgroup$
3
  • $\begingroup$ Thanks for your answer, Mr Huber, but I want to get the "-" as only symbol but ont subtract. $\endgroup$ Mar 22, 2021 at 7:20
  • $\begingroup$ If you want a string form: StringReplace[ToString[list], "->" -> "-"] $\endgroup$ Mar 22, 2021 at 10:42
  • $\begingroup$ This is a good method, but I want to get a dataset in the end. $\endgroup$ Mar 22, 2021 at 14:19

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.