R - 数字序列的范围,或者我怎样才能得到 1:10 的反转 [英] R - Range of number sequences, or how can I get the reverse of 1:10

查看:65
本文介绍了R - 数字序列的范围,或者我怎样才能得到 1:10 的反转的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我似乎找不到找到范围的优雅解决方案.对我来说,这归结为:

I can't seem to find an elegant solution to finding ranges. For me, it would come down to this:

> seq(1:10)
  [1]  1  2  3  4  5  6  7  8  9 10

我想反过来:

function(c(1,2,3,4,5,6,7,8,9,10))
result 1:10

现实世界的问题是我有 1200 个索引,有些是 0,有些是 1:

Real world problem is that I have 1200 indices, some are 0, some are 1:

c(0,0,0,0,0,0,1,1,1,1,1,1,0,0,0,0,1,0,0,1,1,1,1,1,1,0,0,0,0,1,1,1,1,1)

我想要向量中每组 0 和 1 的范围/坐标.

And I would like the ranges/coordinates within the vector for each set of 0s and 1s.

推荐答案

这个简单的解决方案会奏效吗?

Will this simple solution work?

> rev(seq(1:10))
 [1] 10  9  8  7  6  5  4  3  2  1

> range(seq(1:10))
[1]  1 10

这篇关于R - 数字序列的范围,或者我怎样才能得到 1:10 的反转的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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