假设我有序列:
x = c( 1, 1, 0, 0, 1, 0, 1, 1, 1, 0, 0)
Run Code Online (Sandbox Code Playgroud)
在R中是否有一种优雅的方式来返回每个序列1的开始和停止索引?
答案应该是一个2列数组,其中nRows = 1的序列数:
startIndx = [ 1, 5, 7 ]
stopIndex = [ 2, 5, 9 ]
Run Code Online (Sandbox Code Playgroud)
谢谢.
BSL