I'm a new user of expss
package. I have a question about how to add a column to show difference.
For example I have an expss
result as below. I would like to add a column to show the difference between V-engine
and Straight engine
(V-engine - Straight engine
)
Code:
library(expss)
data(mtcars)
mtcars = apply_labels(mtcars,
mpg = "Miles/(US) gallon",
cyl = "Number of cylinders",
disp = "Displacement (cu.in.)",
hp = "Gross horsepower",
drat = "Rear axle ratio",
wt = "Weight (1000 lbs)",
qsec = "1/4 mile time",
vs = "Engine",
vs = c("V-engine" = 0,
"Straight engine" = 1),
am = "Transmission",
am = c("Automatic" = 0,
"Manual"=1),
gear = "Number of forward gears",
carb = "Number of carburetors"
)
mtcars %>%
tab_cells(cyl, disp) %>%
tab_cols(vs) %>%
tab_stat_mean() %>%
tab_pivot()
| | | Engine | |
| | | V-engine | Straight engine |
| --------------------- | ---- | -------- | --------------- |
| Number of cylinders | Mean | 7.4 | 4.6 |
| Displacement (cu.in.) | Mean | 307.1 | 132.5 |
>
Many thanks