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)
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
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.