I am trying to get many lm models work in a function and I need to automatically drop constant columns from my data.table. Thus, I want to keep only columns wit
lm
Check if the variance is zero:
df[, sapply(df, var, na.rm = TRUE) != 0, with = FALSE] # x # 1: 1 # 2: 2 # 3: 3 # 4: NA # 5: 5