Group Abstract Group Abstract

Message Boards Message Boards

1
|
5.2K Views
|
4 Replies
|
2 Total Likes
View groups...
Share
Share this post:

How to align data in Dataset?

Posted 10 years ago

Hello All,

I got a number of columns with data, but how can I align the data to the right. I tried a lot with Alignement->Right but without any success. Default is all to the left. See example.

Dataset[
 <|"0" -> <|"n" -> 19354, "%" -> 34|>
  , "1" -> <|"n" -> 3286, "%" -> 6|>
  , "2" -> <|"n" -> 8578, "%" -> 15|>
  , "3" -> <|"n" -> 22397, "%" -> 39|>
  , "4" -> <|"n" -> 3265, "%" -> 6|>
  , "TT" -> <|"n" -> 55880, "%" -> 100|>
  |>]

enter image description here

Thanks,.....Jos

POSTED BY: Jos Klaps
4 Replies
Posted 10 years ago

As I am trying to practice the Query syntax, I did this alternative coding:

With[
 {displayTable = 
   Grid[Join[{Prepend[Normal@ds[1, Keys], ""]}, (* top label *)
             Join[Transpose@{Keys@#}, Values@#, 2]],
        Alignment -> Right, Dividers -> {{None, Gray}, {None, Gray}}] &},
 ds[displayTable, Values]]

enter image description here

POSTED BY: Gustavo Delfino

Hi Gustavo,

Thanks to let me know. Regards,........Jos

POSTED BY: Jos Klaps

Dataset is not used as visualization. It merely shows it visually, but it is not intended for print or export. It shows it like this such as to give you a quick overview of your data. Not to refine and customize.

You can create a similar visualization using TableForm:

nds = Normal[Normal[Normal[ds]]];
labeltop = nds[[1, 2, All, 1]]
labelleft = nds[[All, 1]]
data = nds[[All, 2, All, 2]]
TableForm[data, TableHeadings -> {labelleft, labeltop}, TableAlignments -> Right]

or using Grid:

nds = Normal[Normal[Normal[ds]]];
labeltop = nds[[1, 2, All, 1]]
labelleft = nds[[All, 1]]
data = nds[[All, 2, All, 2]]
Grid[MapThread[Prepend, {Prepend[data, labeltop], Prepend[labelleft, ""]}], Frame -> True, Dividers -> {{True, True}, {True, True}},  Alignment -> Right]

giving:

enter image description here

POSTED BY: Sander Huisman

Hi Sander,

Thanks for your great support....Jos

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