Re: [R] Indexing vector with repeated values

From: Uwe Ligges <ligges_at_statistik.uni-dortmund.de>
Date: Fri 26 May 2006 - 17:46:10 EST

Andris Jankevics wrote:

> Hi all,
> I have a vector which contains many repeated values.
>
>

>>Z <- c(1,2,3,4,5,1,2,3,4,5,1,2,3,5,5,2,3,4,5)

>
>
> I need to know how many times each number in this vecetor is repeated.
> I can use a command like this:
>
>
>>table (cut(Z,seq(1,5,1)))

Why not simply
  table(Z)
?

>
> (1,2] (2,3] (3,4] (4,5]
> 4 4 3 5
>
> But how can I find a break points for vector with random values and random
> number sequence intervals? Why result for interval (1,2) is 4, if there is
> only 3 values of "1"?

There is no "1" counted, but 4 "2"s, you have not specified an interval with 1 in it.
You were looking for
  table(cut(Z,seq(0,5,1)))
but don't need cut() here at all.

> Can I get from vector Z a smal vector Zs 1,2,3,4,5 ?

seq(min(Z), max(Z))

Uwe Ligges

>
> Thanks a lot!
>
> Andris Jankevics
>
> ______________________________________________
> R-help@stat.math.ethz.ch mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html



R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html Received on Fri May 26 17:49:09 2006

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.1.8, at Fri 26 May 2006 - 18:10:26 EST.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-help. Please read the posting guide before posting to the list.