Reputation: 101
I'm trying to use TableOne [https://cran.r-project.org/web/packages/tableone/tableone.pdf] in R to create a table. The data I'm using looks at patients who have undergone surgery and need a table of their existing medical conditions. I tried with the full dataset (30+ cols), but made a smaller df of just four to try and get this working.
Comorbidities (htn, hl, cv) are coded as TRUE/FALSE; and I have converted them to numeric using:
df$data <- as.numeric(df$data)
I have put my code below, and the associated error.
For reference:
tp is the dataframe
htn/hl/cv are three separate columns, each is True/False within tp
age is a column of continuous within tp
> tp$htn <- as.numeric(tp$htn)
> tp$hl <- as.numeric(tp$hl)
> tp$cv <- as.numeric(tp$cv)
> str(tp)
Classes ‘tbl_df’, ‘tbl’ and 'data.frame': 1199 obs. of 4 variables:
$ htn : num 0 0 0 0 1 0 1 1 1 1 ...
$ hl : num 0 0 0 0 0 0 1 0 1 1 ...
$ cv : num 0 0 1 0 0 0 0 1 1 1 ...
$ age : num 81.2 85.5 80.4 69.4 67.3 ...
> listvars <- tp[c("htn", "hl", "cv", "age")]
> catvars <- tp[c("htn", "hl", "cv")]
> table1 <- CreateTableOne(vars = listvars, data = tp, factorVars = catvars)
**Error in ModuleStopIfNoVarsLeft(vars) : No valid variables.
In addition: Warning message:
In ModuleReturnVarsExist(vars, data) :**
I have attempted to fix it, firstly as above by ensuring all the variables are numeric, not just logical. Secondly, cut the dataset to only four columns as above, as I thought perhaps it required using all variables in the dataset.
I'm unsure how to proceed, any help greatly appreciated.
Upvotes: 1
Views: 2403
Reputation: 325
I'm the maintainer. Please use the following.
listvars <- c("htn", "hl", "cv", "age")
catvars <- c("htn", "hl", "cv")
vars
and factorVars
expect character vectors of variable NAMES.
Upvotes: 1