s-news
[Top] [All Lists]

Re: Extracting vector elements

To: Yong Wang <wang@galton.uchicago.edu>
Subject: Re: Extracting vector elements
From: Prof Brian Ripley <ripley@stats.ox.ac.uk>
Date: Fri, 11 Jun 2004 07:41:27 +0100 (BST)
Cc: Splus Posting <s-news@lists.biostat.wustl.edu>
In-reply-to: <Pine.LNX.4.58.0406110131570.11921@aitken.uchicago.edu>
On Fri, 11 Jun 2004, Yong Wang wrote:

> I have a quick question follow Jonathan's(as below)
> If I wanna have not only the unique elements in an array but also the 
> frequency of each unique elements in the original array, what's the most 
> effcient way to get a quick summary list of such  frequency corresponding 
> to each unique elements?

The answer below suggest ?table, and if you act on that you will see
table()  is the answer to your question.

> On Wed, 9 Jun 2004, Spencer Graves wrote:
> 
> > ?unique or ?table
> > 
> > hope this helps.  spencer graves
> > 
> > Jonathan Dakin wrote:
> > 
> > > Dear S users,
> > >
> > > Is there a simple way of reducing a vector to one in which each 
> > > element is expressed once, no matter how many occurences there are in 
> > > the original ?
> > >
> > > Eg :
> > >
> > > 1,2,2,3,3,3,3,3,4  ---->   1,2,3,4
> > >
> > > I have been using such convoluted means as the intersection with the 
> > > set of integers, or reducing to factor data and then re-converting.  
> > > Clearly there is something I'm missing.  Many thanks.

-- 
Brian D. Ripley,                  ripley@stats.ox.ac.uk
Professor of Applied Statistics,  http://www.stats.ox.ac.uk/~ripley/
University of Oxford,             Tel:  +44 1865 272861 (self)
1 South Parks Road,                     +44 1865 272866 (PA)
Oxford OX1 3TG, UK                Fax:  +44 1865 272595


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