I have excel 2000, google docs, and the latest open office calc available to me. I'm after a solution in any of those, ideally.
I have a multiset of data described by rows of (count, value) pairs. e.g.
count, value
3, 1,
7, 2,
6, 3,
2, 4,
1, 5,
8, 6,
This represents the multiset {1, 1, 1, 2, 2, 2, 2, 2, 2, 2, 3, 3, 3, 3, 3, 3, 4, 4, 5, 6, 6, 6, 6, 6, 6, 6, 6}
I'd like to perform some statistics on the final set, e.g. excel's AVERAGE() or MODE(). How do I do this? How do I 'expand' the (count,value) pairs into a set/array that the spreadsheet program can work on?
Currently I can only do the statistics on the values in the sheet, which obviously aren't correct.
A trivial python implementation of what I'm talking about is below.
set_desc = [
#count, value
(3, 1),
(7, 2),
(6, 3),
(2, 4),
(1, 5),
(8, 6),
]
multiset = []
# [3] * 5 in python would make the list [3,3,3,3,3]
for (count, value) in set_desc:
print "Addding", [value] * count
multiset.extend([value] * count)
sorted_multiset = sorted(multiset)
i0 = (len(sorted_multiset)-1)/2
i1 = (len(sorted_multiset))/2
print "final values in multiset are", sorted_multiset
print "median value(s) lies at index", i0, i1
print ""
print "mean average is", float(sum(sorted_multiset, 0))/len(sorted_multiset)
print "median value is", float(sorted_multiset[i0] + sorted_multiset[i1])/2