# Vector-calculus [duplicate]

I have a table of 200 elements, elements are '0', '1', '2'. I have participate them into groups for 20 elements each one. Then I have calculate how many '0', '1', '2' are in each part. And then in vectors n1, n2, n0 write the answers. For example: n1=(3,4,5,2,3,4,5,6,6,1); so there are 3 elements of '1' in first part and so on. How can I do that?

-

## marked as duplicate by Mr.Wizard♦Apr 14 '14 at 20:03

see Partition and Tally –  george2079 Apr 14 '14 at 10:52
Sorry, I don't understand your question. You say a "table of 200 elements" -- is this a list (vector) or two dimensional table? –  Mr.Wizard Apr 14 '14 at 10:52
All your questions are about the same thing and are closely related. And your two first questions answer this one IMO. –  Öskå Apr 14 '14 at 12:50
antalstrempel, in the future if a question of yours is "put on hold" please do not post a new of nearly identical content; instead edit your question to improve it, to try to address reason for the [on hold]. In this case you didn't even answer my simple question above; please do so. –  Mr.Wizard Apr 14 '14 at 19:27
I have now marked this as a duplicate because by the only way that I can interpret this it is, apart from Partition which you were shown in answer to your prior question. If this is not what you want you can still edit this question to clarify. –  Mr.Wizard Apr 14 '14 at 20:04

I guess this will do what you want! Here an example of the kind of groups of 20 you mentioned. I assume '0', '1', '2' in your elements list are strings.

list = RandomChoice[{"0", "1", "2"}, {10, 20}];


Now the counting is easy. and you get those n0,n1,n2.

Transpose@(Sort[Tally[#]] & /@ ToExpression[list])[[All, All, 2]]


{{2, 9, 8, 7, 7, 9, 4, 10, 7, 8}, {11, 5, 3, 7, 5, 4, 6, 2, 3, 5}, {7, 6, 9, 6, 8, 7, 10, 8, 10, 7}}

As mentioned in the comment here goes the BinCount version.

Transpose[BinCounts[#, {0, 10, 1}] & /@ ToExpression[list]][[1 ;; 3]]

-
BinCounts might be better (this will break if any count happens to be zero) –  george2079 Apr 14 '14 at 14:22