Surprisingly I am not finding an answer to this easy question. I need a pipe-friendly way to count the number of non-zero elements in a vector.
Without piping:
v <- c(1.1,2.2,0,0)
length(which(v != 0))
When I try to do this with pipes I get an error
v %>% which(. != 0) %>% length
Error in which(., . != 0) : argument to 'which' is not logical
A dplyr solution would also help