vec1<- c(0,1,1,1,2,2,2,3,3) length(unique(vec1[vec1!=0])) #[1] 3 vec2<- c(0,2,2,3) length(unique(vec2[vec2!=0])) #[1] 2 A.K.
>Hi. I have a new question. >I need count the different numbers in a vector,but different of zero. >I mean,if I have c(0,2,2,3) the result is 2. If the >vector is c(0,1,1,1,2,2,2,3,3) the result is 3 (3 different values non-zero). ______________________________________________ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.