[6255] in s-news-athena
Re: counting replicated X
daemon@ATHENA.MIT.EDU (Martin Maechler)
Wed Jan 25 03:26:29 1995
From: Martin Maechler <maechler@stat.math.ethz.ch>
Date: Wed, 25 Jan 1995 09:01:08 +0100
To: bshipley@courrier.usherb.ca
Cc: S-news@utstat.toronto.edu
In-Reply-To: <9501241833.AA20965@courrier.usherb.ca> (bshipley@courrier.usherb.ca)
Reply-To: Martin Maechler <maechler@stat.math.ethz.ch>
>>>>> "Bill" == Bill Shipley <bshipley@courrier.usherb.ca> writes:
Bill> Here is a (probably) simple problem which I want to solve without
Bill> using "for" loops: given a vector: x<-c(1,1,1,2,2,3,4,4) I want
Bill> to count the number of replicate values of each unique value in
Bill> x. I.e. I want something like: unique x: 1 2 3 4 # reps : 3 2 1 2.
Bill> Any ideas?
yes: table(x) !!
--------
i.e.,
tx <- table(x)
length(tx) ##-> 4 : contains the number of replicates
## note that the unique values are extracted by
as.numeric(names(tx))
Martin Maechler <maechler@stat.math.ethz.ch> <>< _
Seminar fuer Statistik, SOL F5 _| |_
ETH (Federal Inst. Technology) 8092 Zurich SWITZERLAND |_ _|
phone: x-41-1-632-3408 fax: ...-1086 |_|