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.
長さを指定する数値のベクトルがあるとしましょう。
x = c(3,5,4,10)
次に、cumsum を実行して範囲を取得します。
cumsum(x) 3 8 12 22
1 から始まる範囲のペアを生成するために、それぞれをペアにする方法を教えてください。
文字ベクトルとして推奨:
c("1-3", "3-8", "8-12", "12-22")
paste次のように使用できます。
paste
paste(c(1, cumsum(x))[-(length(x)+1)], cumsum(x), sep = "-") # [1] "1-3" "3-8" "8-12" "12-22"