7

I am having a similar problem to what this user reported. Variables that are numeric and continuous are being treated as categorical. Lets just use the cars dataset as well so that we have something reproducible to work with. Lets say I simply do:

tbl_summary(mtcars)

enter image description here

Most of the variables will be treated as continuous but cyl, gear and carb for instance will be treated as categorical. I understand (per that other question) how to treat ALL of the variables as continuous, but what if I like most of my table and just want to change gear to be treated as continuous for instance? Is that possible?

In my real dataset, the variable I would like to be treated as continuous is already a numeric variable and I don't really see why its being treated as categorical, so I want to specify that gtsummary should treat that specific one as continuous.

Joe Crozier
  • 944
  • 8
  • 20

2 Answers2

5

According to ?tbl_summary, the type argument takes a named list. So, if we need the gear as 'continuous', specify that alone as a list in the type and it will be taken as that type while the other variables will be automatically judged

library(gtsummary)
tbl_summary(mtcars, type = list(gear ~ "continuous"))

-output

enter image description here

akrun
  • 874,273
  • 37
  • 540
  • 662
1

I am having the same issue. Explicitly specifying the data type with the type= argument solves the issue for a standalone summary table.

It causes problems if you want to dynamically supply a list of row variables. It raises error when the listed variable (type = list(gear ~ "continuous2")) is not in the provided list of row variables.

It would be better to be able to globally suppress this functionality.

Enayet
  • 41
  • 5