Is this what you want: > aggregate(X$PL_Pos, list(X$MyDate), sum) Group.1 x 1 2009-08-03 174 2 2009-08-04 -26 3 2009-08-05 614 4 2009-08-06 318 5 2009-08-10 414 6 2009-08-11 -626 7 2009-08-12 544 8 2009-08-13 -106 9 2009-08-17 -146 10 2009-08-19 1004 11 2009-08-20 568 12 2009-08-24 -716 13 2009-08-25 -132 14 2009-08-26 8 15 2009-08-27 622 > You can fix up the column names.
On Fri, Aug 28, 2009 at 12:37 PM, Mark Knecht<markkne...@gmail.com> wrote: > Hi, > I wonder if someone can suggest how to create a new data.frame Y > from X where X$PL_Pos is summed by each unique X$MyDate. Y should end > up with two (or more) columns Y$MyDate and Y$PL_Sum with its value > being the cumsum of all the values in X for that date. - a 'daily > cumsum'. > > Thanks, > Mark > > > TStoDate = function (TSDate) { > X = strptime(TSDate + 19e6L, "%Y%m%d") > return(as.Date(X)) > } > > X = structure(list(EnDate = c(1090803, > 1090804, 1090805, 1090806, 1090806, 1090810, 1090811, 1090812, > 1090813, 1090817, 1090819, 1090820, 1090820, 1090824, 1090825, > 1090825, 1090826, 1090826, 1090827, 1090827, 1090827), PL_Pos = c(174, > -26, 614, 344, -26, 414, -626, 544, -106, -146, 1004, 344, 224, > -716, -176, 44, 354, -346, -296, 564, 354)), .Names = c("EnDate", "PL_Pos"), > class = "data.frame", row.names = c("733", > "734", "3631", "3641", "736", "2403", "2413", "3651", "3661", > "3671", "3681", "3691", "1303", "3701", "1304", "1305", "2432", > "1306", "3712", "1307", "4214")) > > X$MyDate = TStoDate(X$EnDate) > > X > > ______________________________________________ > R-help@r-project.org mailing list > 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. > -- Jim Holtman Cincinnati, OH +1 513 646 9390 What is the problem that you are trying to solve? ______________________________________________ R-help@r-project.org mailing list 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.