0
$\begingroup$

I have a very long list of sublists, where one sublist looks like:

1 1 902 -1 1.013822E-04 0.000000E+00 0.000000E+00 0.000000E+00 1.130107E+00 -6.025446E-01 3.522072E-01 8.825352E-01 0 2 2.599555E+00 1 1 1 1 0.000000E+00 0.000000E+00 0.000000E+00 0.000000E+00 8.993981E-01 2.221197E-02 -1.828014E-01 4.680873E-02 0 2 2.599555E+00 1 1 101 1 1.013822E-04 1.475486E+00 -5.304831E-01 2.460637E+00 2.914779E-01 -1.322933E-01 -1.852007E-01 1.188046E-01 1000002 2 2.599555E+00 1 1 1 1 1.013822E-04 1.475486E+00 -5.304831E-01 2.460637E+00 2.077368E+00 7.570499E-01 -3.498079E-01 1.645024E+00 1000002 2 2.599555E+00

Now I need to count the number of these sublists with the number '902' in its third position. I have used Count[Ev, 902, 2], but that counts also sublists where the sequence '902' appears in some of the other numbers. How can restrict the count only to the number of 902 appearances at the third position?

$\endgroup$
2
  • 3
    $\begingroup$ one sublist looks like what you pasted is not a Mathematica list. A list starts with { and ends with } and elements inside it are separated by commas. May be you can try using InputForm to get it pasted OK here. $\endgroup$ Commented Jan 25 at 11:26
  • 3
    $\begingroup$ Select[yourlist, #[[3]] == 902 &] ? I note that you have been a member for 10+ years and more effort is expected from users with such credentials. $\endgroup$ Commented Jan 25 at 11:30

1 Answer 1

2
$\begingroup$

You can try this:

str = "1 1 902 -1 1.013822E-04 0.000000E+00 0.000000E+00 0.000000E+00 \ 1.130107E+00 -6.025446E-01 3.522072E-01 8.825352E-01 0 2 2.599555E+00 \ 1 1 1 1 0.000000E+00 0.000000E+00 0.000000E+00 0.000000E+00 \ 8.993981E-01 2.221197E-02 -1.828014E-01 4.680873E-02 0 2 2.599555E+00 \ 1 1 101 1 1.013822E-04 1.475486E+00 -5.304831E-01 2.460637E+00 \ 2.914779E-01 -1.322933E-01 -1.852007E-01 1.188046E-01 1000002 2 \ 2.599555E+00 1 1 1 1 1.013822E-04 1.475486E+00 -5.304831E-01 \ 2.460637E+00 2.077368E+00 7.570499E-01 -3.498079E-01 1.645024E+00 \ 1000002 2 2.599555E+00"; Cases[ImportString[str, "Table"], {_, _, 902, ___}] // Length 
$\endgroup$

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.