2013-11-26 138 views

回答

1

使用cumsum

> x <- c(1,0,0,1,1,1) 
> x 
[1] 1 0 0 1 1 1 
> cumsum(x) 
[1] 1 1 1 2 3 4 

合計

> cbind(x, xsum=cumsum(x)) 
    x xsum 
[1,] 1 1 
[2,] 0 1 
[3,] 0 1 
[4,] 1 2 
[5,] 1 3 
[6,] 1 4 
+1

thanks thanks allot jilber – Darellon

相關問題