Consider the following:
lists = Import["G:/Notebooks/Lists.csv"];
col7 = lists [[All, 7]];
For[i=0,i<101,i++,Print[Count[col7,i]]]
This will get a 100 cells printed out but what I really want to do is capture this output to another variable as a list. So far the best way I have figured out is to copy the output, edit the text, and manually paste it back in to a variable. There surely has to be a better way?
Answer
Generally, the solution to this kind of problems is using Table:
Table[Count[col7, i], {i, 100}]
However, in this case I suggest Tally or BinCounts:
Tally[col7]
BinCounts[col7, {0, 100, 1}]
Tally will not list elements that don't appear at all.
Comments
Post a Comment