s-news
[Top] [All Lists]

Re: strange counting function needed

To: "'Leeds, Mark'" <mleeds@mlp.com>, s-news@lists.biostat.wustl.edu
Subject: Re: strange counting function needed
From: "Liaw, Andy" <andy_liaw@merck.com>
Date: Fri, 27 Aug 2004 21:50:48 -0400
Mark,
 
I'm not sure which of the following is what you want, but I guessing it's one of them:
 
> x <- c("AAA", "BBB", "AAA", "CCC", "DDD", "CCC")
> table(x)
x
AAA BBB CCC DDD
  2   1   2   1
> tab <- table(x)
> tab[x]
x
AAA BBB AAA CCC DDD CCC
  2   1   2   2   1   2

HTH,
Andy
 
-----Original Message-----
From: s-news-owner@lists.biostat.wustl.edu [mailto:s-news-owner@lists.biostat.wustl.edu] On Behalf Of Leeds, Mark
Sent: Friday, August 27, 2004 9:17 PM
To: s-news@lists.biostat.wustl.edu
Subject: [S] strange counting function needed

i played around and i can't figure out the following "
 
i have a vector of strings called temp such as
 
"AAA" "BBB" "AAA" "CCC" "DDD"
 
so temp1 = "AAA" etc.
 
what i want to return is a vector of numbers
representing how many times the string is in the vector
 
so in this case i would want
 
2    1    2   1    1
 
with looping this is not a problem but
i can't figure out how to do it without looping.
 
i thought
 
temp2_sum(temp == ( temp[1:length(temp)] ))
 
might work but it doesn't.
 
 
                                        thanks

------------------------------------------------------------------------------
Notice: This e-mail message, together with any attachments, contains information of Merck & Co., Inc. (One Merck Drive, Whitehouse Station, New Jersey, USA 08889), and/or its affiliates (which may be known outside the United States as Merck Frosst, Merck Sharp & Dohme or MSD and in Japan, as Banyu) that may be confidential, proprietary copyrighted and/or legally privileged. It is intended solely for the use of the individual or entity named on this message. If you are not the intended recipient, and have received this message in error, please notify us immediately by reply e-mail and then delete it from your system.
------------------------------------------------------------------------------

<Prev in Thread] Current Thread [Next in Thread>