I'm a beginner in ruby, trying to use it to help me analyse biological data. I need to try and match a set of data (numbers in an array) to another with a certain specificity (e.g number+/- 0.25) I have come up with this (so far) to change one data set into ranges, instead of numbers:
def range(arr)
c = []
arr.each do |b|
b = (b-0.25..b+0.25)
b = b.to_a
c << b
end
c = c.flatten
return c
end
the code gives the desired array, however I always get
TypeError: can't iterate from Float.
how can I fix that?
Background
this is a sample of my practical data:
119.0456 119.0714 119.0721 119.0737 120.0772 130.0746 131.0737 136.0721 140.0951 143.0697 154.038 154.0744 154.1108 155.0949 156.054 169.053 170.1422 171.0646 171.0686 174.0644 174.0795 180.0539 182.1059
I need to match it to a theoretical set, which I need to generate withtin a tolerance of 0.002 I am working on the code step by step to generate my theoretical set, since I'm still new to coding, and just wanted to know how to create a range of +/- 0.002 around my theoretical set to match it to the practical one.