[R] data frame cumulative row sum

Rui Barradas ruipbarradas at sapo.pt
Mon Dec 8 21:37:52 CET 2014


Hello,

If your dataset is named 'dat', try

dat$z <- cumsum(dat$y)


Hope this helps,

Rui Barradas

Em 08-12-2014 08:18, Ragia Ibrahim escreveu:
> Hi,
> Kindly I had a data frame looks like this
> x y
> 1 3
> 2 2
> 3 1
> 4 3
> and I want to add column z that sum cumulativly like this
> x y z
> 1 3 3
> 2 2 5
> 3 1 6
> 4 3 9
>
> how to do this?
> Regards
> Ragia
>   		 	   		
> 	[[alternative HTML version deleted]]
>
> ______________________________________________
> R-help at r-project.org mailing list -- To UNSUBSCRIBE and more, see
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>



More information about the R-help mailing list