Question: I have ~150 logical variables and want to remove trivial ones (all data values are FALSE). How can I do that with dplyr?

What I'm doing (maybe I don't need that at all, still learning). I have data where each data point is categorized. The trick is that the same point may have multiple categories, so it's not a factor:

```
y | x | domain
------------------
0 | 1 | dogs,animals
1 | 5 | cats,animals

```

And I'd like to build a prediction model for `y`. I converted this structure (outside R) into logical columns:

```
y | x | d_dogs | d_cats | d_animals
-----------------------------------
0 | 1 |    T   |    F   |    T
1 | 5 |    F   |    T   |    T

```

and am building a regression model on that. (Categories are nested on themselves, but that's another topic).

But some categories have too little data points (all, or almost all values are `F`), so I want to remove them. Without dplyr I do:

```
keep.columns <- sapply(colnames(data), function(n) {
    c <- data[,n];
    !is.logical(c) || sum(c) > 1
})
data[, keep.columns]

```

But curious if I can do that easier.

Answer: 
We could use `Filter`

```
 Filter(function(x) !is.logical(x) | sum(x)>1, data)

```
To find columns with trivial (identical) values, you could try this:

```
df <- data.frame(a = c(1,1,1,1,1), b = c(1,2,3,4,5), c = c("a","a","a","a","a"))

df %>% 
summarise_each(funs(n_distinct))

```

Output:

```
  a b c
1 1 5 1

```

i.e., cols "a" and "c" have only 1 unique/distinct value