[R] new data.frame summed by date

Mark Knecht markknecht at gmail.com
Fri Aug 28 18:37:57 CEST 2009


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




More information about the R-help mailing list