Plot a histogram without zero values in R

histogram, r

Solution

You can just use subsetting like this:

hist( a[ !a==0 ])

You can check it works like so:

table(is.na(c))
FALSE  TRUE 
 443    57 

length(a[!a==0])
[1] 443

Problem

I'd like to exclude all zero values from a histogram. Until now to do so I created a new object and transformed all zero values to NAs but I hoped there would be some easier way without creating new objects. Example code: ``` set.seed(45) a<-sample(0:10,500,replace=T) c<-ifelse(a!=0,a,NA) hist(c) ```

Original source