Togaware DATA MINING
Desktop Survival Guide
by Graham Williams
Google

Remove Variables with no Variance

We also only want columns where there is some variance in the values, so also remove those columns with a minimum value equal to the maximum. Again, use is made of lapply to apply a function (in this case max and min) to the data.



> rmcols <- as.numeric(lapply(dat, min, na.rm=T)) ==
            as.numeric(lapply(dat, max, na.rm=T))
> rmcols <- rev(seq(1,ncol(dat))[rmcols])
> for (i in rmcols) dat[[i]] <- NULL
> ncol(dat)
[1] 59



Copyright © 2004-2006 Graham.Williams@togaware.com
Support further development through the purchase of the PDF version of the book.
Brought to you by Togaware.