Message Boards Message Boards

0
|
5575 Views
|
3 Replies
|
0 Total Likes
View groups...
Share
Share this post:
GROUPS:

Conditional sum on list of lists.

Posted 11 years ago
Hi
This question has been probably raised but when i did searching on the community i got nil result (??) and  some notification of community respect .So ,the thing is that when i have a list : {{a(t),b(t),c(t)},{a(t-1),b(t-1),c(t-1)},....{a(t-n),b(t-n),c(t-n)}} can i use "IF"  to a(t) and check it against a(t-1) and if they are equal  when sum "b" elements. ?Can it be recursively to the further pairs -- i.e. a(t-1) and a(t-2)....?
POSTED BY: Artur Kotarski
3 Replies
Posted 11 years ago
the second  option
POSTED BY: Artur Kotarski
Do you want to add all the b(i) for which a(i) == a(t)?  Or doe the sum stop at the first triple for which a(i) does not equal a(t)?
POSTED BY: Bruce Miller
Posted 11 years ago
Split[list, (First[#1] == First[#2]) &] /. {_Integer, c_Integer, _Real} :> {c}
f = Flatten[Map[{Plus @@ #} &, %], 1] // Flatten

1 Can it be written more simply?
2. Can it be written with using "If"?
POSTED BY: Artur Kotarski
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard

Group Abstract Group Abstract