


Usually, the columns would represent exposure or treatment groups, not outcomes, and we want to compare those groups with respect to the distribution of baseline characteristics, and for this purpose having percentages add up to 100% within columns makes the most sense. However, this is not really the standard application for these kinds of tables (at least not the one I have in mind). In my version, it is easier to compare the different types of outcomes with respect to variables like sex, while in the original version it is easier to compare sexes with respect to outcomes. This is now looking pretty similar to the original blog post, but admittedly there are still some differences: the sexes are inverted (the original blog post got it wrong) I added units to the continuous variables I include the number of individuals in each column under the column heading the percentages are different, because I think they should add to 100% within a column, and in the original blog post they add to 100% along a row (except for the Total column, which adds to 100% within the column). To achieve the same result, we need to customize the output further, and in this case that involves using the slightly more complicated “default” (i.e. non-formula) interface to table1.įirst, we set up our labels differently, using a list:

This looks better, but still not quite the same as the original blog post: in the blog post the “Total” column is on the left, while we have it on the right the two “Death” strata (Melanoma and Non-melanoma) should be grouped together under a common heading the continuous variables Age and Thickness show only Means (SD) (with a ±), and not Median like the table1 default output most values are displayed with two significant digits rather than three (I will not concern myself with the footnote here, but it could be added as well). To improve things, we can create factors with descriptive labels for the categorical variables ( sex and ulcer), label each variable the way we want, and specify units for the continuous variables ( age and thickness), like this: Note that the table1 package uses a familiar formula interface, where the variables to include in the table are separated by ‘+’ symbols, the “stratification” variable (which creates the columns) appears to the right of a “conditioning” symbol ‘|’, and the data argument specifies a ame that contains the variables in the formula.īut because we don’t have nice labels for the variables and categories, it doesn’t look great.
