Regression model with variables with different lengths

Sometimes when you are running a regression model with variables that have different lengths, r will prompt with the following error message:


Error in model.frame.default(formula = bmi ~ age, drop.unused.levels = TRUE) : 
  variable lengths differ (found for 'age')

This error message is mainly due to the fact that either bmi or age has different number of NA observations. The first step is to remove the NAs from the data frame at hand

Remove NAs

df2=df1[complete.cases(df1),]



Introduction to the Analysis of Survival Data in the Presence of Competing Risks

 https://www.ncbi.nlm.nih.gov/pmc/articles/PMC4741409/