1
$\begingroup$

In order to study the relationship between an endemic disease in a certain place and the health habits of local residents (health habits are divided into good and not good enough), a medical team randomly investigated 100 cases of the disease (called case group), and 100 people (called control group) in the population without the disease, and obtained the following data:(The data is in the following picture)

enter image description here

How to reproduce the data format in the picture into mathematica. In other words, if the operation makes the table data in the picture displayed in mathematica?

How to add total column and total line? See the figure below.The final effect is as follows

enter image description here

$\endgroup$
1

1 Answer 1

4
$\begingroup$
$Version

"13.2.0 for Mac OS X x86 (64-bit) (November 18, 2022)"

Clear["Global`*"]

data1 = {{"", "not good enough", "good"}, {"case group", 40, 
    60}, {"control group", 10, 90}};

Grid[data1, Frame -> All, ItemSize -> 10]

enter image description here

data2 = {{"study groups", "health habits", 
    SpanFromLeft}, {SpanFromAbove, "not good enough", 
    "good"}, {"case group", 40, 60}, {"control group", 10, 90}};

Grid[data2, Frame -> All, ItemSize -> 10, 
 Alignment -> {Center, Center}]

enter image description here

$\endgroup$
4
  • $\begingroup$ TIL: SpanFromLeft and SpanFromAbove! Even though they are right and center in Grid's documentation, I never noticed them. +1 $\endgroup$
    – Victor K.
    Jan 31 at 0:05
  • $\begingroup$ How to add total column and total line? $\endgroup$
    – csn899
    Jan 31 at 0:07
  • $\begingroup$ data1 = {{"", "not good enough", "good", "total"}, {"case group", 40, 60, 100}, {"control group", 10, 90, 100}, {"total", 50, 150, 200}}; Grid[data1, Frame -> All, ItemSize -> 10] $\endgroup$
    – csn899
    Jan 31 at 0:25
  • $\begingroup$ Add a total row and column at the bottom and right of the table. Can I automatically calculate the sum of the corresponding row and column data? $\endgroup$
    – csn899
    Jan 31 at 0:26

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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