DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 3 of 3

Thread: help applying formulae

  1. #1
    Join Date
    Apr 2011

    help applying formulae

    Hello all

    Could anyone please help me apply the following formulae to the set of data below?
       col(1)                col(2)     col(3)
    6178/32032003,    98925,        2
    6178/32033001,    98920,        1
    6178/32033003,    98925,        5
    6178/32033004,    98925,        3
    6178/32034001,    98925,        3
    6178/32034001,    98920,	1
    6178/32034003,    98925,	8
    6178/32034004,    98925,	4
    6178/32035001,    98925,	1
    6178/32035004,    98925,	1
    6178/32036001,    98925,	2
    	                               col(1)	            =  (col(2) x col(3)) + (col(2) x col(3)) / (col(3) + col(3))
    Formula 1) avg col(2) for 6178/32034001  =  (98925  x 3)      + (98920  x 1)      / (3      + 1)
    		              (col(2) x total of col(3)) + (col(2) x total of col(3)) / (total of col(3) + total of col(3))
    Formula 2) total avg col(2) = (98925  x 29)              + (98920  x 2)               / (             29 + 2)
    a) The above CSV strings is formed of variables of a struct and each struct object is stored as an element of a vector, the vector in this case would be having 11
    elements where each element is formed of 3 struct variables

    b) Formula 1): col(2) values against each col(1) value that appears more than once e-g "6178/32034001" appears twice
    - col(2) value against the first appearance of "6178/32034001" is "98925" and col(2) value against the second appearance of "6178/32034001" is "98920"
    - col(3) value against "98925" is "3" and col(3) value against "98920" is "1"

    c) Formula 2): sum of col(3) values against each of the col(2) values
    - sum of values of col(3) that appear against "98925" i-e col(2) is 29 in above case (2+5+3+3+8+4+1+1+2 = 29)
    - sum of values of col(3) that appear against "98920" i-e col(2) is 2 in above case (1+1 = 2)

    Many Thanks

  2. #2
    Join Date
    Dec 2003
    Your example is pretty short, so you need to know for yourself if the data is always sorted or organized in any way ahead of time or if you need to do that yourself. If it is NOT, you need to sort the data by col 1 first.

    Once it is sorted, it just becomes a set of loops over the data. Since it is sorted, looping over col1 ensures that if the next data and the current data are the same (or current and previous if you prefer that logic) if there is any match of that data point, so you can simply apply the formula as needed using that idea, saving the new data in a new column or whatever you like.

    Same idea works for C though you should resort the data off column 2.

    There is a more annoying way to do it where you keep track of each data point manually rather than sort but there is no reason to do it -- you spend as much time checking to see if your current is something you have already seen before as you would have sorting it ahead of time and the algorithm is a lot more complex. Its almost never a good idea to do it that way unless your data set is very unusual, for example if you only had 2 possible values in col 1, it would be better to do it this way as the algorithm is simple enough and it would process large data sets fast.

  3. #3
    Join Date
    Apr 2011
    Thanks for your help Jonnin :)

Similar Threads

  1. Applying styles to <option> elements
    By m3kan1cal in forum Web
    Replies: 0
    Last Post: 08-27-2007, 04:47 PM
  2. Applying Styles To Selected Contents Via CSS
    By freesoft_2000 in forum VB Classic
    Replies: 1
    Last Post: 09-27-2006, 12:31 AM
  3. Replies: 1
    Last Post: 05-08-2006, 01:34 PM
  4. Problem applying simple XSLT to XML
    By gregclark in forum XML
    Replies: 3
    Last Post: 08-26-2005, 05:07 AM
  5. Applying Exchange Rules To Incoming Messages w/Attachments.
    By John McAuliffe in forum Enterprise
    Replies: 3
    Last Post: 05-18-2000, 06:49 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
HTML5 Development Center
Latest Articles
Questions? Contact us.
Web Development
Latest Tips
Open Source

   Development Centers

   -- Android Development Center
   -- Cloud Development Project Center
   -- HTML5 Development Center
   -- Windows Mobile Development Center