So, basically you want to remove all columns that are all zero? Is that it?
I don't have a data to test with, but something like this will do it:
train[colSums(train)>0]
Edit: (in reply to #3)
@TalhaAsif that's not what your main thread says. It talks about columns with just 0's.
For your changed requirement, try something like this.
train[lapply(train, function(x) length(unique(x))) > 1]