[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: uniq -c
From: |
Mike Miller |
Subject: |
Re: uniq -c |
Date: |
Fri, 27 Aug 2004 12:59:38 -0500 (CDT) |
On Fri, 27 Aug 2004, John W. Eaton wrote:
On 27-Aug-2004, Mike Miller <address@hidden> wrote:
| Is there a way to count repetitions of a value in a vector? In unix/linux
| we could use "uniq -c" to count consecutive identical lines. Is there
| something analogous in Octave? If not, can one of you come up with a
| clever scheme for doing this within Octave? (I've been on this list long
| enough to know that the answer is yes to that last question!)
|
| I really just need the counts and not a list of the values being counted.
| Hmm... I just realized that if I had an ordinary 'uniq' function, I could
| get the "uniq -c" this way (for column vector x):
|
| [NN,XX] = hist(x,uniq(x))
|
| Then [NN,XX] would be the "uniq -c" output and XX would actually equal
| uniq(x).
Octave has
create_set
intersection
union
Thanks! So create_set(X) essentially does "vec(X) | sort | uniq" (pardon
my use of unixy pipes) on the matrix X. I needed the sorting, and this
happened to give me what I needed:
[NN,XX]=hist(x,create_set(x)); NN
We might consider having a uniq(X) operation that doesn't sort the data.
We can always do uniq(sort(X)), as in UNIX/Linux. If uniq operated on
rows of a matrix, that would work for me, but it would probably be most
useful with column vectors.
Thanks again.
Mike
-------------------------------------------------------------
Octave is freely available under the terms of the GNU GPL.
Octave's home on the web: http://www.octave.org
How to fund new projects: http://www.octave.org/funding.html
Subscription information: http://www.octave.org/archive.html
-------------------------------------------------------------
- uniq -c, Mike Miller, 2004/08/27
- uniq -c, John W. Eaton, 2004/08/27
- Re: uniq -c,
Mike Miller <=