I need to extract into a new column the number of observations per level from a Cox regression object. If I run:
res <- coxph(Surv(age, status) ~ score, data = df)
res %>% tbl_regression(exp = T) %>% add_n(location = 'level')
I get a similar table: Table (Credit)
Evidently, add_n() takes the number of observations from somewhere.
I looked at the object but I only saw where the total number of observations is stored, not per level. I googled but nothing relevant came up.
Answer provided by @AllanCameron in the comments: