- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Get Direct Link
- Report Inappropriate Content
Command to get number of identical entries in a list
I have a list from which I want to get the number of times 0's (and 1's) appear in it.
m = {0, 0, 0, 0, 0, 0, 0, 1, 1, 1};
nzeros = N Items (m) <1; show (nzeros);
does not seem to work to get the number of times 0 appear in m.
(I get nzeros = 0)
What is the correct way to get the number of times an identical entry appears on a list (I am on JMP 13)?
When it's too good to be true, it's neither
1 ACCEPTED SOLUTION
Accepted Solutions
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Get Direct Link
- Report Inappropriate Content
Re: Command to get number of identical entries in a list
Names Default to Here( 1 );
m = {0, 0, 0, 0, 0, 0, 0, 1, 1, 1};
mm = Matrix( m );
nZeros = Sum( mm == 0 );
nOnes = Sum( mm == 1 );
Show( nZeros, nOnes );
4 REPLIES 4
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Get Direct Link
- Report Inappropriate Content
Re: Command to get number of identical entries in a list
Names Default to Here( 1 );
m = {0, 0, 0, 0, 0, 0, 0, 1, 1, 1};
mm = Matrix( m );
nZeros = Sum( mm == 0 );
nOnes = Sum( mm == 1 );
Show( nZeros, nOnes );
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Get Direct Link
- Report Inappropriate Content
Re: Command to get number of identical entries in a list
Ok, This works. So I have to convert a list to a Matrix.
When it's too good to be true, it's neither
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Get Direct Link
- Report Inappropriate Content
Re: Command to get number of identical entries in a list
Hi @Neo ,
you can try this as well:
Names Default to Here( 1 );
m = {0, 0, 0, 0, 0, 0, 0, 1, 1, 1};
nZeros = n items (loc(m, 0));
nOnes = n items (loc (m, 1));
no conversion to matrix but i do not see any advantage in this case.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Get Direct Link
- Report Inappropriate Content
Re: Command to get number of identical entries in a list
If it's really zeros and ones, couldn't you just sum for the ones?
Names default to here(1);
m = {0, 0, 0, 0, 0, 0, 0, 1, 1, 1};
n_ones = sum(m);
n_zeros = nitems(m)-n_ones;
Though the other two are probably better in general.
Vince Faller - Predictum