Closed raheems closed 5 years ago
@raheems, can you please provide some example code generating a table you want to edit?
My guess at what you are looking for could be done by editing the rgroups
attribute of a qwraps2_summary_table
object. For example, the object both
from the vignette has the str:
str(both)
'qwraps2_summary_table' chr [1:12, 1:5] "10.4" "33.9" "20.09 ± 6.03" "71.1" "472" "230.72 ± 123.94" ...
- attr(*, "dimnames")=List of 2
..$ : chr [1:12] "min" "max" "mean (sd)" "min" ...
..$ : chr [1:5] "mtcars2 (N = 32)" "cyl_factor: 6 cylinders (N = 7)" "cyl_factor: 4 cylinders (N = 11)" "cyl_factor: 8 cy
linders (N = 14)" ...
- attr(*, "rgroups")= Named int [1:4] 3 3 3 3
..- attr(*, "names")= chr [1:4] "Miles Per Gallon" "Displacement" "Weight (1000 lbs)" "Forward Gears"
Edit the names of the attribute:
names(attr(both, "rgroups"))[1] <- "New name, with a p-value of 0.001"
both
mtcars2 (N = 32) | cyl_factor: 6 cylinders (N = 7) | cyl_factor: 4 cylinders (N = 11) | cyl_factor: 8 cylinders (N = 14) | P-value | |
---|---|---|---|---|---|
New name, with a p-value of 0.001 | |||||
min | 10.4 | 17.8 | 21.4 | 10.4 | |
max | 33.9 | 21.4 | 33.9 | 19.2 | |
mean (sd) | 20.09 ± 6.03 | 19.74 ± 1.45 | 26.66 ± 4.51 | 15.10 ± 2.56 | P < 0.0001 |
Displacement | |||||
min | 71.1 | 145.0 | 71.1 | 275.8 | |
max | 472 | 258.0 | 146.7 | 472.0 | |
mean (sd) | 230.72 ± 123.94 | 183.31 ± 41.56 | 105.14 ± 26.87 | 353.10 ± 67.77 | P < 0.0001 |
Weight (1000 lbs) | |||||
min | 1.513 | 2.620 | 1.513 | 3.170 | |
max | 5.424 | 3.460 | 3.190 | 5.424 | |
mean (sd) | 3.22 ± 0.98 | 3.12 ± 0.36 | 2.29 ± 0.57 | 4.00 ± 0.76 | P < 0.0001 |
Forward Gears | |||||
Three | 15 (47) | 2 (29) | 1 (9) | 12 (86) | |
Four | 12 (38) | 4 (57) | 8 (73) | 0 (0) | |
Five | 5 (16) | 1 (14) | 2 (18) | 2 (14) |
Use of paste
or sprintf
could make the edit more robust.
@raheems, I have added an example towards the end of the vignette to address this issue. Will you please review the change in commit 05cf3b7 and let me know if it answers your question? Thanks.
This is very helpful. I've tried and it works. Thank you!!
Excellent! I'm glad to the example was helpful.
Would you please give an example code of how to add p-value to the table labeling the row group instead of say, mean (sd).
The example in the vignette shows the following.
both[grepl("mean \\(sd\\)", rownames(both)), "P-value"] <- pvals
Thank you