R 中的算术级数 [英] Arithmetic Progression series in R

查看:70
本文介绍了R 中的算术级数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是这个论坛的新手.我想以前有人问过这样的问题,但是我不确定这是否是我想要的.

I am new to this forum. I guess something like this has been asked before but, I am not really sure if that is what I want.

我有一个这样的序列,

1 2 3 4 5 8 9 10 12 14 15 17 18 19

所以,我想要做的是,获取形成系列的所有数字,即属于该集合的数字都应该与前一个元素有一个恒定的差异,并且元素的最小数量应该是3 个.

So, what I wish to do is this, get all the numbers which form a series,i.e.the numbers that belonging to that set should all have a constant difference with the previous element, and also the minimum number of elements should be 3 in that set.

即,我可以看到 (1,2,3,4,5) 形成一个这样的系列,其中数字出现在间隔 1 之后,并且该集合的总大小为 5,其中满足最小阈值标准.(1,3,5) 形成了这样一种模式,其中数字出现在间隔 2 之后.

i.e., I can see that (1,2,3,4,5) forms one such series in which numbers appear after an interval of 1 and the total size of this set is 5 which satisfies the minimum threshold criteria. (1,3,5) forms one such a pattern in which the numbers appear after an interval of 2.

(8,10,12,14) 形成另一个这样的模式,间隔为 2.所以,如你所见,重复的间隔可以是任何.

(8,10,12,14) forms another such pattern with an interval of 2. So, as you can see, the interval of repetition can be anything.

另外,对于特定的集合,我想要最大的集合.我不想要,(8,10,12)(虽然它满足 3 和常数差异的最小阈值)作为输出,并且只是我想要的最大长度,即 (8,10,12,14).

Also, for a particular set, I want its maximal one. I dont want, (8,10,12) (although it satisfies the minimum threshold of 3 and constant difference ) as the output and only of the maximal length I want, i.e. (8,10,12,14).

同样,对于 (1,2,3,4,5) ,我不想要 (1,2,3)(2,3,4,5) 作为输出,只有我想要的最大长度,即 (1,2,3,4,5).

Similarly, for, (1,2,3,4,5) , I dont want (1,2,3) or (2,3,4,5) as the output, only the MAXIMAL LENGTH ONE I WANT, i.e. (1,2,3,4,5).

如何在 R 中执行此操作?

How can I do this in R?

也就是说,我想要任何组成基本 AP 系列的任何集合,但有任何差异,但该系列中的总值应大于 3,并且应为最大值.

That is, I want any set which forms a basic AP series with any difference, however the total value should be greater than 3 in that series and it should be maximal.

Edit2:我尝试在 R 中使用 rleacf 但这并不能完全解决我的问题.

I have tried using rle and acf in R but that doesnt entirely solves my problem.

Edit3:当我做 acf 时,它基本上给了我可以使用的最大峰值差异.但是,我想要所有可能的差异.另外,rle 是完全不同的.它给了我最长的相似数字连续序列.在我的情况下不存在.

When I did acf, it basically gave me the maximum peak difference that I could have used. However, I want all the differences possible. Also, rle is just way different. It gave me the longest continuous sequence of similar numbers. Which is not there in my case.

推荐答案

如果您正在寻找连续数字的序列,那么 cgwtools::seqle 会找到它们你以同样的方式 rle 找到重复值的序列.

If you are looking for sequences of consecutive numbers, then cgwtools::seqle will find them for you in the same way rle finds a sequence of repeated values.

在基本上形成这种序列的数据的任何子集的一般情况下,例如您引用的 8,10,12,14 情况,您的标准非常普遍难以满足.您必须从系列的每个元素开始,并前瞻性地搜索 x[j] +1, x[j]+2, x[j]+3 ...无止境.这建议使用一些基于树的算法.

In the general case of basically any subset of your data which form such a sequence, such as the 8,10,12,14 case you cite, your criteria are so general as to be very difficult to satisfy. You'd have to start at each element of your series and do a forward-looking search for x[j] +1, x[j]+2, x[j]+3 ... ad infinitum. This suggests using some tree-based algorithms.

这篇关于R 中的算术级数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆