I am just wondering if there is an easy way to count
in a numeric vector how many numbers don't have
replicates.
For example,
a=c(1,1,2,2,3,4,5), how can I know there are three
numbers (3, 4 and 5) without replicates?
How about:
length(table(a)[table(a) == 1])
?
Ray Brownrigg
On Thu, 2004-12-16 at 13:40 -0800, Jun Ding wrote:
Hi,
I am just wondering if there is an easy way to count
in a numeric vector how many numbers don't have
replicates.
For example,
a=c(1,1,2,2,3,4,5), how can I know there are three
numbers (3, 4 and 5) without replicates?
Thank you!
-Original Message-
From: [EMAIL PROTECTED]
[mailto:[EMAIL PROTECTED] On Behalf Of Peter Dalgaard
Sent: Thursday, December 16, 2004 5:43 PM
To: Ray Brownrigg
Cc: [EMAIL PROTECTED]; [EMAIL PROTECTED]
Subject: Re: [R] counting numbers without replicates in a vector
Ray
Jun Ding wrote:
Hi,
I am just wondering if there is an easy way to count
in a numeric vector how many numbers don't have
replicates.
For example,
a=c(1,1,2,2,3,4,5), how can I know there are three
numbers (3, 4 and 5) without replicates?
How about using ?table:
tab - table(a)
unq -
On 12/16/04 13:40, Jun Ding wrote:
Hi,
I am just wondering if there is an easy way to count
in a numeric vector how many numbers don't have
replicates.
For example,
a=c(1,1,2,2,3,4,5), how can I know there are three
numbers (3, 4 and 5) without replicates?
Take a look at unique()
--
?duplicated and ?unique might be of interest to you ...
But I think an easier way is:
z-table(a)
length(z)-sum(z1)
This gives you the count.
names(z)[z==1] gives you the actual values
(The quotes can be removed by explicitly calling print with argument
quote=FALSE)
-- Bert Gunter
Genentech
table will probably do. The following is probably is what you want:
a - c(1,1,2,2,3,4,5)
a.tab - table (a)
a.tab
a
1 2 3 4 5
2 2 1 1 1
as.vector(which (a.tab == 1))
[1] 3 4 5
Cheers,
Yu
Jun Ding wrote:
Hi,
I am just wondering if there is an easy way to count
in a numeric vector how many