[R] different values of a vector

Marc Schwartz (via MN) mschwartz at mn.rr.com
Tue Mar 14 19:04:50 CET 2006

On Tue, 2006-03-14 at 18:45 +0100, Arnau Mir wrote:
> Hello.
> I have a vector of length 2771 but it has only 87 different values.
> How can I obtain them?
> Thanks,
> Arnau.

If you just want the unique values themselves, you can use:


For example:

> v
 [1] "b" "b" "c" "a" "a" "a" "c" "c" "c" "c"

> unique(v)
[1] "b" "c" "a"

If you wanted counts of each unique value, you can use table():

> table(v)
a b c 
3 2 5 


Marc Schwartz

More information about the R-help mailing list