Let say I have the following data frame in R:
df1 <- data.frame(Item_Name = c("test1","test2","test3"), D_1=c(1,0,1),
D_2=c(1,1,1), D_3=c(11,3,1))
I would like to create a function that would delete columns with no variance
(e.g. in this case, it would remove column D_2 because it has only 1 value)
I know that I could check it by hand, but in reality my data is very large and I would like to automate it. Any idea?
Filteris a useful function here. I will filter only for those where there is more than 1 unique value.i.e.