Eazye
Eazye

Reputation: 21

Is there a way to reorganize and combine 4 tables to match a format of a table I need in R studio?

I have 4 tables that I would like to combine and reformat to match the format of a template.

The 4 tables are:


print(outcome.table)
   Group AE Status Count  Percent
1      B         0     0      NaN
2      B         1     0      NaN
3      B         2     0      NaN
4      B         3     0      NaN
5      B         4     0      NaN
6      A         0     0  0.00000
7      A         1     1 33.33333
8      A         2     0  0.00000
9      A         3     1 33.33333
10     A         4     1 33.33333
11     C         0     0      NaN
12     C         1     0      NaN
13     C         2     0      NaN
14     C         3     0      NaN
15     C         4     0      NaN

> print(severity.table)
  Group Severity Count Percent
1     B        1     0     NaN
2     B        2     0     NaN
3     B        3     0     NaN
4     A        1     1      50
5     A        2     0       0
6     A        3     1      50
7     C        1     0     NaN
8     C        2     0     NaN
9     C        3     0     NaN

> print(serious.table)
  Group Serious Count Percent
1     B       0     0     NaN
2     B       1     0     NaN
3     A       0     3     100
4     A       1     0       0
5     C       0     0     NaN
6     C       1     0     NaN

> print(drug.table)
   Group Drug related Count Percent
1      B            0     0     NaN
2      B            1     0     NaN
3      B            2     0     NaN
4      B            3     0     NaN
5      B            4     0     NaN
6      B            5     0     NaN
7      A            0     0       0
8      A            1     0       0
9      A            2     0       0
10     A            3     0       0
11     A            4     2     100
12     A            5     0       0
13     C            0     0     NaN
14     C            1     0     NaN
15     C            2     0     NaN
16     C            3     0     NaN
17     C            4     0     NaN
18     C            5     0     NaN

The template table is:

enter image description here

Basically, I am working on an ongoing clinical trial and I have pulled adverse event data for the patients that are currently in the study. A quick explanation of the tables I have created. For example, the outcome.table counts the number of adverse events in the adverse event outcome category 0 for Group A, counts the number of ae for category 1 for Group A, and so on for the other categories in each Group (A, B, and C). The percents are the proportion of counts in a particular category for a specific Group (A, B, or C). Sorry if this is at all confusing. I may not be explaining it well. I basically did the same thing for the 3 other tables. Now I would like to combine and reorganize the tables to match the template I posted above. It may not be possible and I may have to go back and redo my tables but just want to see if anyone has any advice for this. TIA!

I have tried to use tidyr and dplyr, but I am not getting the outcome I would like. I may need to first reorganize each table separately then merge them together. Any advice will help

Upvotes: 0

Views: 19

Answers (0)

Related Questions