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]]
my.data$z <- cumsum(my.data$y) Yes, the function you need is even in your message subject.> On Dec 8, 2014, at 12:18 AM, Ragia Ibrahim <ragia11 at hotmail.com> wrote: > > 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.Don McKenzie Research Ecologist Pacific Wildland Fire Sciences Lab US Forest Service Affiliate Faculty School of Environmental and Forest Sciences University of Washington dmck at uw.edu
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. >
On 08/12/14 21:18, Ragia Ibrahim wrote:> 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?(1) Learn to use R. This is very basic; read some introductory material. Start with "An Introduction to R" from the R web site. This is analogous to the assertion that you shouldn't be driving a car if you haven't a clue how to drive. (2) Try: X$z <- cumsum(X$y) where X is the data frame in question. cheers, Rolf Turner -- Rolf Turner Technical Editor ANZJS