Troubleshoot error with column identification

Hello - I'm a new R user and was trying to use final fit package to simplify some of my tables etc.

I keep running into an error with the code where it can't find the variable diabetes. Although when I list it, it is there in the dataset. I've pasted the code and error message below. Diabetes is a "yes/no" variable - could that be part of the issue?

Many thanks.

diabetes <- as.factor(diabetesdata[,"dm"])
explanatory = c("hdl", "age")
dependent =  "diabetes"  # diabetes as outcome
diabetesdata %>%
  summary_factorlist(dependent, explanatory, p=TRUE, add_dependent_label=TRUE)

list(diabetes). # I did this to check the variable and it's fine

Error: Can't subset columns that don't exist.
x Column diabetes doesn't exist.

I think the problem is that the variable diabetes exists but there is not a column named diabetes in the data frame diabetesdata. The function is looking inside the data frame. Try changing your definition of diabetes to

diabetesdata$diabetes <- as.factor(diabetesdata[,"dm"])

You can run


just before and after that command to see that a new column is made.

This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.