Reputation: 23
I am trying to create summary tables. I want to split these by site and have a "Total" column.
However, when I try to rename multiple columns AND use add_overall(), I get the following error:
"Error: Error in label=
argument input. Select from ‘yearDOB’, ‘sex_code’, ‘agecat’". Here is the code when I get the error:
childdemotable <- matchesinterim %>%
select(yearDOB, sex_code, agecat, site_0) %>% # keep only columns of interest
tbl_summary(
by = site_0, # stratify entire table by outcome
statistic = list(all_categorical() ~ "{N} ({p}%)"), # stats and format for categorical columns
type = all_categorical() ~ "categorical", # force all categorical levels to display
label = list( # display labels for column names
site_0 ~ "Site",
yearDOB ~ "Year of Birth",
sex_code ~ "Gender",
agecat ~ "Age Category",
missing_text = "(Missing)")
) %>%
add_overall()
Here is the code for only using add_overall:
childdemo %>% tbl_summary(by=site_0,
missing_text = "(Missing)") %>%
add_overall() %>%
modify_header(label ~ "Characteristic")
And the code when I only rename the columns.
childdemotable <- matchesinterim %>%
select(yearDOB, sex_code, agecat, site_0) %>% # keep only columns of interest
tbl_summary(
by = site_0,
statistic = list(all_categorical() ~ "{N} ({p}%)"),
type = all_categorical() ~ "categorical",
label = list(
site_0 ~ "Site",
yearDOB ~ "Year of Birth",
sex_code ~ "Gender",
agecat ~ "Age Category",
missing_text = "(Missing)")
)
I have no idea what is going wrong. I've tried to only rename one column and use add_overall() which does work. But it doesn't work when renaming multiple columns. I then tried going column by column but that wasn't working either.
Upvotes: 0
Views: 1399
Reputation: 21
I met the same problem. So you need to delete site_0 ~ "Site" in your list for label. Because it's a strata and not in the table anymore.
label = list(
yearDOB ~ "Year of Birth",
sex_code ~ "Gender",
agecat ~ "Age Category")
I actually strongly suggest in this label part, the variables not in the table can be simply ignored, which will make it much easier to use. Otherwise, people need to edit the list of label each single time.
Upvotes: 2
Reputation: 11680
It looks like you're just missing an end parenthesis in the label argument.
But will need a reproducible example to be sure.
childdemotable <-
matchesinterim %>%
select(yearDOB, sex_code, agecat, site_0) %>% # keep only columns of interest
tbl_summary(
by = site_0,
statistic = list(all_categorical() ~ "{N} ({p}%)"),
type = all_categorical() ~ "categorical",
label = list(
site_0 ~ "Site",
yearDOB ~ "Year of Birth",
sex_code ~ "Gender",
agecat ~ "Age Category"),
missing_text = "(Missing)"
)
Upvotes: 0