Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
数値ベクトル [1 2 3 4 7 8 9 10 15 16 17] がある場合、そのベクトルの連続要素を分離する複数のベクトルが返されるように分割するにはどうすればよいですか? すなわち [1 2 3 4] [7 8 9 10] [15 16 17]。matlabでこれを行う方法の答えを見つけましたが、Rのみを使用しています.
ありがとう。
別のオプション:
split(vec, cummax(c(1,diff(vec))))
結果
$`1` [1] 1 2 3 4 $`3` [1] 7 8 9 10 $`5` [1] 15 16 17