[R] cumsum output
Felipe Carrillo
mazatlanmexico at yahoo.com
Mon May 10 23:09:54 CEST 2010
Hi: Thanks to Dennis and Fernando for your help reordering the levels.
Now I have a different issue:
I am trying to get the cumulative weekly values using cumsum and it
appears to output the wrong values. Here's my dataset:
winter <- structure(list(week = c(26L, 27L, 28L, 29L, 30L, 31L, 32L, 33L,
34L, 35L, 36L, 37L, 38L, 39L, 40L, 41L, 42L, 43L, 44L, 45L, 46L,
47L, 48L, 49L, 50L, 51L, 52L, 1L, 2L, 3L, 4L, 5L, 6L, 7L, 8L,
9L, 10L, 11L, 12L, 13L, 14L, 15L, 16L, 17L, 18L, 19L, 20L, 21L,
22L, 23L, 24L, 25L), BY2009 = c(0L, 95L, 436L, 809L, 3668L, 9437L,
42700L, 141135L, 486474L, 1109095L, 1459053L, 1990285L, 2643088L,
2988446L, 3131437L, 3280320L, 4237821L, 4270316L, 4285178L, 4292388L,
4302153L, 4308999L, 4314066L, 4320267L, 4323312L, 4429542L, 4430725L,
4430920L, 4437775L, 4448036L, 4452215L, 4452865L, 4453105L, 4453270L,
4454459L, 4455322L, 4455884L, 4457234L, 4457422L, 4457901L, 4458671L,
4458671L, 4459229L, 4459543L, 4459690L, NA, NA, NA, NA, NA, NA,
NA), BY2008 = c(0L, 0L, 77L, 201L, 360L, 2736L, 12216L, 29530L,
129104L, 452783L, 650994L, 744624L, 873807L, 985627L, 1056887L,
1092128L, 1106148L, 1126926L, 1148620L, 1163636L, 1177036L, 1186223L,
1189830L, 1192634L, 1195051L, 1200342L, 1216558L, 1217456L, 1218014L,
1218723L, 1219695L, 1219756L, 1220128L, 1223214L, 1233322L, 1237617L,
1238499L, 1241092L, 1241128L, 1241361L, 1241604L, 1241604L, 1241674L,
1241946L, 1242254L, 1242388L, 1242428L, 1242428L, 1242428L, 1242428L,
1242428L, 1242428L), BY2007 = c(0L, 0L, 0L, 10775L, 14941L, 19899L,
36120L, 65521L, 100472L, 133660L, 279704L, 384711L, 570008L,
729690L, 937227L, 1077921L, 1206196L, 1250470L, 1277549L, 1296477L,
1306914L, 1336898L, 1355293L, 1381139L, 1385712L, 1417707L, 1421386L,
1422429L, 1432065L, 1433589L, 1434416L, 1441425L, 1441658L, 1442091L,
1442091L, 1443194L, 1443451L, 1443579L, 1443645L, 1443715L, 1444250L,
1444679L, 1444776L, 1444776L, 1444776L, 1444776L, 1444776L, 1444776L,
1444776L, 1444776L, 1444776L, 1444776L), BY2006 = c(0L, 707L,
3097L, 11957L, 36387L, 77272L, 150064L, 355585L, 700078L, 1363051L,
1889460L, 2521413L, 3371904L, 4214582L, 4660569L, 5218721L, 5550753L,
5725079L, 5805680L, 5854376L, 5952947L, 6056510L, 6205979L, 6284060L,
6466538L, 6468696L, 6485262L, 6489289L, 6491944L, 6493056L, 6493623L,
6496218L, 6501194L, 6507530L, 6507824L, 6509582L, 6509873L, 6510076L,
6510526L, 6511624L, 6512412L, 6512607L, 6513139L, 6513139L, 6513139L,
6513139L, 6513139L, 6513139L, 6513139L, 6513306L, 6513306L, 6513306L
), BY2005 = c(0L, 0L, 868L, 2912L, 6976L, 13025L, 22424L, 35728L,
80900L, 323055L, 799919L, 1512453L, 2570862L, 4685880L, 6196222L,
7334435L, 7667627L, 7826447L, 7920826L, 8269708L, 8308998L, 8338699L,
8385957L, 8455794L, 8463678L, 8513016L, 8535184L, 8554581L, 8573978L,
8589962L, 8598650L, 8599850L, 8601473L, 8602764L, 8604120L, 8604827L,
8605702L, 8606577L, 8606799L, 8607682L, 8607682L, 8607682L, 8607811L,
8607811L, 8607811L, 8607811L, 8607811L, 8607811L, 8607811L, 8607811L,
8607811L, 8607811L)), .Names = c("week", "BY2009", "BY2008",
"BY2007", "BY2006", "BY2005"), class = "data.frame", row.names = c(NA,
-52L))
apply(winter[,2:6],2,cumsum)
Felipe D. Carrillo
Supervisory Fishery Biologist
Department of the Interior
US Fish & Wildlife Service
California, USA
More information about the R-help
mailing list