help: divide a list into other two - Printable Version +- HP Forums (https://www.hpmuseum.org/forum) +-- Forum: HP Calculators (and very old HP Computers) (/forum-3.html) +--- Forum: HP Prime (/forum-5.html) +--- Thread: help: divide a list into other two (/thread-3917.html) |
help: divide a list into other two - salvomic - 05-19-2015 09:23 PM hi, to calculate MIRR (modified IRR) I need to divide list L1 in this way: if L1(j) < 0 -> flneg(j), if L1(j) >=0 -> flpos(j) with Code:
in both lists there is 0 at the correspondent place in the other list (i.e. {-1, 2, 3, -4} -> {-1, 0, 0, -4} and {0, 2, 3, 0} I need {-1, -4} and {2, 3} please, help TIA! Salvo RE: help: divide a list into other two - Didier Lachieze - 05-19-2015 10:01 PM This should work: Code: flneg:=MIN(L1,0); flpos:=MAX(L1,0); You need to do it in two steps: flneg:=remove(0,MIN(L1,0)) doesn't work. RE: help: divide a list into other two - salvomic - 05-19-2015 10:06 PM (05-19-2015 10:01 PM)Didier Lachieze Wrote: This should work: Thank you! quite ok, but there is a possibility that the original list has zeros among items (i.e {-100, 100, 100, 0, 0, 0, -50, -50, 100}) Any help for this? TIA salvo RE: help: divide a list into other two - Didier Lachieze - 05-19-2015 10:14 PM As in your program example you were testing L1(j)<0 and L1(j)>0 I assumed you wanted to discard the zeros. So, where do you want the zeros to fall? In both lists? RE: help: divide a list into other two - salvomic - 05-19-2015 10:18 PM (05-19-2015 10:14 PM)Didier Lachieze Wrote: As in your program example you were testing L1(j)<0 and L1(j)>0 I assumed you wanted to discard the zeros. I think only in flpos, positive... precisely, to calc MIRR I must have a list of positive values (and 0) and a list of negative, in the same order of original. Actually I've this list {-180000, 100000 (5 times), -100000 (5 times), 0 (9 times), 200000} that's {-180000, 100000, 100000, 100000, 100000, 100000, -100000, -100000, -100000, -100000, -100000, 0,0,0,0,0,0,0,0,0, 200000} The 9 zeros are period to discount... EDIT (see here page 193) positive list must also have a first element prepend, zero: {0, 100000, ..., 0, 0, ..., 200000} but this is another 0 (fix, I think) However, maybe the leading zeros are ok, I'm trying another way... RE: help: divide a list into other two - Didier Lachieze - 05-19-2015 11:08 PM Try this: Code: flneg:=remove("x->x>=0,L1"); RE: help: divide a list into other two - salvomic - 05-20-2015 06:57 AM (05-19-2015 11:08 PM)Didier Lachieze Wrote: Try this: (05-19-2015 11:15 PM)DrD Wrote:(05-19-2015 10:01 PM)Didier Lachieze Wrote: This should work: thank you both! this tip is very interesting. |