datasumz 0.1.0 → 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 682a06d820218ec6aab1c9a258155e64147dd866
4
- data.tar.gz: 88999b95ea9ec3bba491fa3fe699bfeed12f7df4
3
+ metadata.gz: 1efbdf86410044bd4d0f67e720d9529d708f736b
4
+ data.tar.gz: ee5da3ee0d6ea25224cbe06d6b3b925aeb37567a
5
5
  SHA512:
6
- metadata.gz: 9ca27718d65d61abf16ffdc1edf936b4f21950d2ec59f3fecbca32ca94fdac3114f55d53e9e4637c8448f53fea2b21fae92ba7d7c9fc9b8e6709eabdce4cc3cf
7
- data.tar.gz: cfa458f21dea3d1bf5923d02e4a4ee4ef033cccce9bdc6f4858b598fe4aa441157758614ab4bc27222c1d6b37c895022287a5b2a20f561b75010bc33f7e029f2
6
+ metadata.gz: 09a3acb31b77d1dfd846493d604c53ee5d35e6714d9418c933ac1c9e2406a814993d73b2eabef93ab9059af0e3fcaaad55736887bd9451481544bbf6eb1a1baf
7
+ data.tar.gz: b88286f3554ce986bc194342da9869df0663811f61728a72285258e11b91f4ac5f2b9c3814ce064843e38f2c24421f785684e659d1bc053755277a26e117b5b0
data/README.md CHANGED
@@ -8,4 +8,8 @@ A Ruby gem to neatly and quickly summarize data.
8
8
 
9
9
  Generate common central tendency statistics and measures of dispersion for numerical data.
10
10
 
11
- Note: Currently handles only single vectors.
11
+ Note: Currently handles only single vectors.
12
+
13
+ #### **freq**
14
+
15
+ Generates a table of frequencies with counts and percentages.
data/lib/datasumz.rb CHANGED
@@ -3,6 +3,7 @@
3
3
  require 'datasumz/version'
4
4
  require 'datasumz/core_extensions/enumerable'
5
5
  require 'datasumz/describer'
6
+ require 'datasumz/frequency'
6
7
 
7
8
  module DataSumz
8
9
  class << self
@@ -16,5 +17,12 @@ module DataSumz
16
17
  d.describe
17
18
  end # def descr
18
19
 
20
+ # Generates a table of frequencies with counts and percentages.
21
+ #
22
+ # @return [Hash]
23
+ def freq(array)
24
+ f = Frequency.new(array)
25
+ f.compute
26
+ end # def freq
19
27
  end # class Self
20
28
  end # module DataSumz
@@ -0,0 +1,29 @@
1
+ # encoding: utf-8
2
+
3
+ module DataSumz
4
+ class Frequency
5
+
6
+ attr_reader :data
7
+
8
+ private
9
+
10
+ def initialize(_data)
11
+ @data = _data
12
+ end # def initialize
13
+
14
+ def compute
15
+ table = Hash.new(Array.new)
16
+ total = @data.length
17
+ hist = @data.each_with_object(Hash.new(0)){ |m,h| h[m] += 1 }.sort_by{ |k,v| v }
18
+ hist.each do |bin|
19
+ name = bin[0]
20
+ n = bin[1]
21
+ per_total = ((n.to_f / total.to_f) * 100).round(2)
22
+ table[name] = [n, per_total]
23
+ end
24
+ table
25
+ end # def compute
26
+
27
+ public(:initialize, :compute)
28
+ end # class Frequency
29
+ end # module DataSumz
@@ -7,7 +7,7 @@ module DataSumz
7
7
 
8
8
  # Current minor release.
9
9
  # @return [Integer]
10
- MINOR = 1
10
+ MINOR = 2
11
11
 
12
12
  # Current patch level.
13
13
  # @return [Integer]
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: datasumz
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Michelle Pellon
@@ -110,6 +110,7 @@ files:
110
110
  - lib/datasumz/core_extensions/enumerable/sd.rb
111
111
  - lib/datasumz/core_extensions/enumerable/sum.rb
112
112
  - lib/datasumz/describer.rb
113
+ - lib/datasumz/frequency.rb
113
114
  - lib/datasumz/version.rb
114
115
  homepage: https://github.com/mpellon/datasumz
115
116
  licenses: