I have a list {{x1,y1},{x2,y2}...}
a list {z1,z2...}
, I want to create a new list {{x1,w1},{x2,w2}...}
, where wi=0.5
if yi<zi
and wi=-0.5
otherwise. I attack this problem by the following code. However, how to avoid creating a new list lsNew
? I think it is a redundancy.
ls = {{1, 2}, {2, 3}, {1, 5}};
v = {2, 7, 8};
lsNew = Transpose[Insert[Transpose[ls], v, 3]]
lsWanted={#[[1]], If[#[[2]] < #[[3]], 0.5, -0.5]} & /@ lsNew