MathGroup Archive 2009

[Date Index] [Thread Index] [Author Index]

Search the Archive

Map conditional sums by date

  • To: mathgroup at smc.vnet.net
  • Subject: [mg99849] Map conditional sums by date
  • From: "Charles L. Snyder" <clsnyder at gmail.com>
  • Date: Sat, 16 May 2009 05:20:19 -0400 (EDT)

Hi

I want to (ultimately) use Manipulate to provide date selections
(year, months, days) to create a BarChart. I am able to get the
results from my data in a kludgy way. The data is in the form {{yr,
mo, day, h,min,sec}, code, amount}, as seen below:

mydata={{2009, 2, 5, 0, 0, 0}, 54161, 3.27`}, {{2006, 8, 23, 0, 0,
  0}, 54163, 3}, {{2007, 12, 5, 0, 0, 0}, 43280, 17.25`}, {{2009, 2,
5,
   0, 0, 0}, 54161, 3.27`}}

I want to conditionally total the amounts (3rd column), by yr OR by
month OR by day; which I can do with :

Select[mydata, #[[1, 2]] == 7 &]
(* would give me all the rows in which July (7th mo) is the month, for
example*)
OR
Select[mydata, #[[1, 1]] == 2008 &]
(* would give me all the rows in which 2008 is the year *)

I can sum the amounts with:
Total[#[[3]] & /@ %]

I need basic help with putting these into a function, but ultimately I
want to be able to select yr or mo or day of week via Manipulate and
get the total....

My failed attempts:

(* parameters are yrmoday -> 1 is year, 2 is mo, 3 is day, and x is
the specific year or month or day*)

sumbydate[x_, yrmoday_] :=
 If[#[[1, yrmoday]] == x, myresult += #[[3]], myresult += 0] & /@
  mydata; myresult

OR

(* this would be sum by month, if it worked...)

sumbydate[x_, yrmoday_] := If[#[[1, yrmoday]] == x, res += #[[3]], res
+= 0] & /@ temp; Map[
 sumrvubydate2[#] &, {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12}]

Thanks!


  • Prev by Date: Re: Random choice
  • Next by Date: Why "InputForm[x,NumberMarks->False]" can not return correctly in my
  • Previous by thread: Re: Preventing swapping (high memory use)
  • Next by thread: Re: Map conditional sums by date