cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
Try the Materials Informatics Toolkit, which is designed to easily handle SMILES data. This and other helpful add-ins are available in the JMP® Marketplace
Choose Language Hide Translation Bar
Neo
Neo
Level VI

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

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 );

View solution in original post

4 REPLIES 4

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 );
Neo
Neo
Level VI

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
ron_horne
Super User (Alumni)

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.

vince_faller
Super User (Alumni)

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