|
DATA MINING
Desktop Survival Guide by Graham Williams |
|
|||
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
|