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.
たとえば、整数のベクトルがあり、c(1,2,0,3,4)0を区切り文字にして、を取得しlist(c(1,2), c(3,4))ます。使用できるライブラリ関数はありますか?
c(1,2,0,3,4)
list(c(1,2), c(3,4))
私が知っているライブラリ関数はありませんが、独自に作成できます。
split.vec <- function(vec, sep = 0) { is.sep <- vec == sep split(vec[!is.sep], cumsum(is.sep)[!is.sep]) } split.vec(c(1,2,0,3,4), 0) # $`0` # [1] 1 2 # # $`1` # [1] 3 4