To select columns with multiple values, regardless of type:
uniquelength <- sapply(d,function(x) length(unique(x))) d <- subset(d, select=uniquelength>1)
?
(Oh, the Roman question is right - it can also knock out your column 5)
May ( change : thanks to comments!)
isfac <- sapply(d,inherits,"factor") d <- subset(d,select=!isfac | uniquelength>1)
or
d <- d[,!isfac | uniquelength>1]
Ben bolker
source share