Convert data.frame into flextable
Arguments
- x
A data.frame
- vanilla
logical
- fontsize
Numeric
- digits
integer indicating the position of decimal place
- showid
logical if TRUE, show id
- ...
Further arguments to be passed to df2flextable()
Value
An object of class flextable
Examples
data(acs,package="moonBook")
library(dplyr)
gaze(acs) %>% myft()
name
levels
stats
age
Mean ± SD
63.3 ± 11.7
sex
Female
287 (33.5%)
Male
570 (66.5%)
cardiogenicShock
No
805 (93.9%)
Yes
52 (6.1%)
entry
Femoral
312 (36.4%)
Radial
545 (63.6%)
Dx
NSTEMI
153 (17.9%)
STEMI
304 (35.5%)
Unstable Angina
400 (46.7%)
EF
Mean ± SD
55.8 ± 9.6
height
Mean ± SD
163.2 ± 9.1
weight
Mean ± SD
64.8 ± 11.4
BMI
Mean ± SD
24.3 ± 3.3
obesity
No
567 (66.2%)
Yes
290 (33.8%)
TC
Mean ± SD
185.2 ± 47.8
LDLC
Mean ± SD
116.6 ± 41.1
HDLC
Mean ± SD
38.2 ± 11.1
TG
Mean ± SD
125.2 ± 90.9
DM
No
553 (64.5%)
Yes
304 (35.5%)
HBP
No
356 (41.5%)
Yes
501 (58.5%)
smoking
Ex-smoker
204 (23.8%)
Never
332 (38.7%)
Smoker
321 (37.5%)
gaze(sex~.,acs) %>% myft()
name
levels
Female (N=287)
Male (N=570)
p
age
Mean ± SD
68.7 ± 10.7
60.6 ± 11.2
<.001
cardiogenicShock
No
275 (95.8%)
530 (93%)
.136
Yes
12 (4.2%)
40 (7%)
entry
Femoral
119 (41.5%)
193 (33.9%)
.035
Radial
168 (58.5%)
377 (66.1%)
Dx
NSTEMI
50 (17.4%)
103 (18.1%)
.012
STEMI
84 (29.3%)
220 (38.6%)
Unstable Angina
153 (53.3%)
247 (43.3%)
EF
Mean ± SD
56.3 ± 10.1
55.6 ± 9.4
.387
height
Mean ± SD
153.8 ± 6.2
167.9 ± 6.1
<.001
weight
Mean ± SD
57.2 ± 9.3
68.7 ± 10.3
<.001
BMI
Mean ± SD
24.2 ± 3.6
24.3 ± 3.2
.611
obesity
No
194 (67.6%)
373 (65.4%)
.580
Yes
93 (32.4%)
197 (34.6%)
TC
Mean ± SD
188.9 ± 51.1
183.3 ± 45.9
.124
LDLC
Mean ± SD
117.8 ± 41.2
116.0 ± 41.1
.561
HDLC
Mean ± SD
39.0 ± 11.5
37.8 ± 10.9
.145
TG
Mean ± SD
119.9 ± 76.2
127.9 ± 97.3
.195
DM
No
173 (60.3%)
380 (66.7%)
.077
Yes
114 (39.7%)
190 (33.3%)
HBP
No
83 (28.9%)
273 (47.9%)
<.001
Yes
204 (71.1%)
297 (52.1%)
smoking
Ex-smoker
49 (17.1%)
155 (27.2%)
<.001
Never
209 (72.8%)
123 (21.6%)
Smoker
29 (10.1%)
292 (51.2%)
fit=lm(mpg~hp*wt,data=mtcars)
gaze(fit) %>% myft()
Estimate
Std. Error
t value
Pr(>|t|)
lower
upper
(Intercept)
49.808
3.605
13.816
<.001
42.424
57.193
hp
-0.120
0.025
-4.863
<.001
-0.171
-0.070
wt
-8.217
1.270
-6.471
<.001
-10.818
-5.616
hp:wt
0.028
0.007
3.753
<.001
0.013
0.043
Residual SE: 2.153 on 28 DF, Multiple R^2: 0.8848, Adjusted R^2: 0.8724
F-statistic: 71.66 on 3 and 28 DF, p-value: 2.981e-13
library(survival)
fit=coxph(Surv(time,status) ~rx,data=anderson1)
gaze(fit) %>% myft()
coef
se(coef)
z
Pr(>|z|)
HR
lower
upper
rxControl
1.572
0.412
3.812
<.001
4.817
2.147
10.809
n=42, events=30, Likelihood ratio test=16.35 on 1 df (p<.001)
# \donttest{
gaze(sex+Dx~.,data=acs,show.p=TRUE,show.total=TRUE,show.n=TRUE,shiw.missing=TRUE) %>% myft()
sex (N)
Female (N=287)
Male (N=570)
name
levels
N
NSTEMI (N=50)
STEMI (N=84)
Unstable Angina (N=153)
total (N=287)
p
N
NSTEMI (N=103)
STEMI (N=220)
Unstable Angina (N=247)
total (N=570)
p
age
Mean ± SD
287
70.9 ± 11.4
69.1 ± 10.4
67.7 ± 10.7
68.7 ± 10.7
.177
570
61.1 ± 11.6
59.4 ± 11.7
61.4 ± 10.6
60.6 ± 11.2
.133
cardiogenicShock
No
287
49 (98%)
73 (86.9%)
153 (100%)
275 (95.8%)
<.001
570
100 (97.1%)
183 (83.2%)
247 (100%)
530 (93%)
<.001
Yes
1 (2%)
11 (13.1%)
0 (0%)
12 (4.2%)
3 (2.9%)
37 (16.8%)
0 (0%)
40 (7%)
entry
Femoral
287
22 (44%)
45 (53.6%)
52 (34%)
119 (41.5%)
.013
570
36 (35%)
88 (40%)
69 (27.9%)
193 (33.9%)
.022
Radial
28 (56%)
39 (46.4%)
101 (66%)
168 (58.5%)
67 (65%)
132 (60%)
178 (72.1%)
377 (66.1%)
EF
Mean ± SD
240
54.8 ± 9.1
52.3 ± 10.9
59.4 ± 8.8
56.3 ± 10.1
<.001
483
55.1 ± 9.4
52.4 ± 8.9
59.1 ± 8.7
55.6 ± 9.4
<.001
height
Mean ± SD
255
154.2 ± 5.1
155.7 ± 5.4
152.6 ± 6.7
153.8 ± 6.2
.002
509
167.5 ± 5.7
168.7 ± 6.0
167.3 ± 6.4
167.9 ± 6.1
.055
weight
Mean ± SD
256
57.2 ± 10.3
57.4 ± 9.0
57.1 ± 9.1
57.2 ± 9.3
.978
510
67.5 ± 8.4
68.8 ± 10.9
69.0 ± 10.6
68.7 ± 10.3
.479
BMI
Mean ± SD
255
24.1 ± 4.3
23.6 ± 3.2
24.5 ± 3.5
24.2 ± 3.6
.215
509
24.1 ± 2.6
24.1 ± 3.4
24.6 ± 3.4
24.3 ± 3.2
.205
obesity
No
287
35 (70%)
60 (71.4%)
99 (64.7%)
194 (67.6%)
.528
570
71 (68.9%)
149 (67.7%)
153 (61.9%)
373 (65.4%)
.301
Yes
15 (30%)
24 (28.6%)
54 (35.3%)
93 (32.4%)
32 (31.1%)
71 (32.3%)
94 (38.1%)
197 (34.6%)
TC
Mean ± SD
277
196.3 ± 52.7
180.7 ± 45.7
191.1 ± 53.1
188.9 ± 51.1
.192
557
192.6 ± 54.3
184.1 ± 42.6
178.7 ± 44.6
183.3 ± 45.9
.036
LDLC
Mean ± SD
276
127.7 ± 39.5
111.0 ± 40.0
118.3 ± 41.8
117.8 ± 41.2
.088
557
125.4 ± 47.1
118.9 ± 39.1
109.5 ± 39.2
116.0 ± 41.1
.002
HDLC
Mean ± SD
277
40.1 ± 13.8
39.5 ± 11.2
38.5 ± 10.8
39.0 ± 11.5
.627
557
38.4 ± 10.9
38.1 ± 10.9
37.4 ± 10.9
37.8 ± 10.9
.655
TG
Mean ± SD
280
112.5 ± 51.1
112.3 ± 87.2
126.3 ± 76.0
119.9 ± 76.2
.316
562
138.0 ± 100.2
104.3 ± 65.5
144.3 ± 114.2
127.9 ± 97.3
<.001
DM
No
287
25 (50%)
54 (64.3%)
94 (61.4%)
173 (60.3%)
.240
570
71 (68.9%)
154 (70%)
155 (62.8%)
380 (66.7%)
.219
Yes
25 (50%)
30 (35.7%)
59 (38.6%)
114 (39.7%)
32 (31.1%)
66 (30%)
92 (37.2%)
190 (33.3%)
HBP
No
287
19 (38%)
28 (33.3%)
36 (23.5%)
83 (28.9%)
.084
570
43 (41.7%)
122 (55.5%)
108 (43.7%)
273 (47.9%)
.016
Yes
31 (62%)
56 (66.7%)
117 (76.5%)
204 (71.1%)
60 (58.3%)
98 (44.5%)
139 (56.3%)
297 (52.1%)
smoking
Ex-smoker
287
8 (16%)
13 (15.5%)
28 (18.3%)
49 (17.1%)
.184
570
34 (33%)
53 (24.1%)
68 (27.5%)
155 (27.2%)
.002
Never
37 (74%)
57 (67.9%)
115 (75.2%)
209 (72.8%)
13 (12.6%)
40 (18.2%)
70 (28.3%)
123 (21.6%)
Smoker
5 (10%)
14 (16.7%)
10 (6.5%)
29 (10.1%)
56 (54.4%)
127 (57.7%)
109 (44.1%)
292 (51.2%)
gaze(Dx+sex~cardiogenicShock,data=acs,show.p=TRUE) %>% myft()
Dx (N)
NSTEMI (N=153)
STEMI (N=304)
Unstable Angina (N=400)
name
levels
Female (N=50)
Male (N=103)
p
Female (N=84)
Male (N=220)
p
Female (N=153)
Male (N=247)
p
cardiogenicShock
No
49 (98%)
100 (97.1%)
1.000
73 (86.9%)
183 (83.2%)
.535
153 (100%)
247 (100%)
1.000
Yes
1 (2%)
3 (2.9%)
11 (13.1%)
37 (16.8%)
0 (0%)
0 (0%)
gaze(Dx+sex+HBP~cardiogenicShock,data=acs,show.p=TRUE) %>% myft()
Dx
sex
(N)
NSTEMI
Female
(N=50)
NSTEMI
Male
(N=103)
STEMI
Female
(N=84)
STEMI
Male
(N=220)
Unstable Angina
Female
(N=153)
Unstable Angina
Male
(N=247)
name
levels
No (N=19)
Yes (N=31)
p
No (N=43)
Yes (N=60)
p
No (N=28)
Yes (N=56)
p
No (N=122)
Yes (N=98)
p
No (N=36)
Yes (N=117)
p
No (N=108)
Yes (N=139)
p
cardiogenicShock
No
19 (100%)
30 (96.8%)
1.000
42 (97.7%)
58 (96.7%)
1.000
23 (82.1%)
50 (89.3%)
.567
106 (86.9%)
77 (78.6%)
.145
36 (100%)
117 (100%)
1.000
108 (100%)
139 (100%)
1.000
Yes
0 (0%)
1 (3.2%)
1 (2.3%)
2 (3.3%)
5 (17.9%)
6 (10.7%)
16 (13.1%)
21 (21.4%)
0 (0%)
0 (0%)
0 (0%)
0 (0%)
# }