different values of a vector

classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

different values of a vector

Arnau Mir Torres-3
Hello.

I have a vector of length 2771 but it has only 87 different values.
How can I obtain them?

Thanks,

Arnau.

______________________________________________
[hidden email] mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Reply | Threaded
Open this post in threaded view
|

Re: different values of a vector

Marc Schwartz (via MN)
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:

  unique(vector)

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)
v
a b c
3 2 5


HTH,

Marc Schwartz

______________________________________________
[hidden email] mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Reply | Threaded
Open this post in threaded view
|

Re: different values of a vector

Andy Bunn
In reply to this post by Arnau Mir Torres-3
> -----Original Message-----
> From: [hidden email]
> [mailto:[hidden email]]On Behalf Of Arnau Mir
> Sent: Tuesday, March 14, 2006 12:45 PM
> To: [hidden email]
> Subject: [R] different values of a vector
>
>
> Hello.
>
> I have a vector of length 2771 but it has only 87 different values.
> How can I obtain them?

It depends on what obtain means. This should get you started.
foo <- sample(1:87,2771,T)
table(foo) #or...
levels(as.factor(foo))


>
> Thanks,
>
> Arnau.
>
> ______________________________________________
> [hidden email] mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide!
> http://www.R-project.org/posting-guide.html
>

______________________________________________
[hidden email] mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Reply | Threaded
Open this post in threaded view
|

Re: different values of a vector

Sundar Dorai-Raj
In reply to this post by Arnau Mir Torres-3
?unique

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.
>
> ______________________________________________
> [hidden email] mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html

______________________________________________
[hidden email] mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html