samedi 19 mai 2018

Grouping values with condition

Suppose I have the following sorted data:

[1] 0.06997360 0.09154285 0.10607553 0.10607631 0.10652390 0.10857691
[7] 0.10858633 0.10858633 0.10870369 0.18790912 0.18792473 0.19509030
[13] 0.20040993 0.22548593 0.22550167 0.22593338 0.22893103 0.23196562
[19] 0.25901025 0.30231663 0.30245132 0.30246287 0.34893528 0.34938294
[25] 0.34943865 0.45200544 0.45658957 0.45673815 0.46432602 0.48493226
[31] 0.58318915 0.58618472 0.66311458 0.66311774 0.69777062 0.69782017
[37] 0.70456743 0.70754232 0.71668759 0.71744870 0.71780786 0.77227751
[43] 0.79785928 0.79823416 0.79831632 0.79832545 0.79863813 0.79880086
[49] 0.91610076 0.91611498 0.91611830 0.91612582 0.91612582 0.91614856

Now I want to group them because many of them are almost equal. Let's say the condition if two values x[i] and x[i+1] are in one group is if (x[i+1]-x[i]<0.01) so the 3rd up to the 9th value would be in one group. These values should all be replaced (for example) with their mean. I don't know how to do this ... Does anybody have a good idea how to come up with this or does even a function exist for this problem?

Aucun commentaire:

Enregistrer un commentaire