1
$\begingroup$

I have the following basic question. I have created the following lists of number

list1= {0.17280394634580676`, 0.16592518527179198`,  0.16565012961313136`, 0.16913887913796202`, 0.17532555997800134`, 0.1709799900459552`, 0.1727886004102705`, 0.17309929761671264`,  0.16684725512423282`, 0.19030846458674544`}
list2 = {0.17386342603139585`, 0.19088582236184554`, 0.23203374070590962`, 0.2369946021621591`, 0.1952022726800119`, 0.23686981987007244`, 0.1980693337605245`, 0.23829147261528855`,   0.14379878667926133`, 0.18123073864910402`}

and i want to select only these elements that have simultaneously a larger value from 0.17 in list1 and a value that is lower than 0.19 in list2 and append them in a new list.

Any ideas?

$\endgroup$
2
$\begingroup$
criteria = {criterion1, criterion2} = {GreaterThan[.17], LessThan[.19]};

Join @@ MapThread[Select[#]@#2 &, {criteria, {list1, list2}}]
{0.172804, 0.175326, 0.17098, 0.172789, 0.173099, 0.190308, 
 0.173863,0.143799, 0.181231}

"how can I also find the positions in lists1 and 2 of each element that is appented in the joint list?"

KeySelect[criterion1] @ PositionIndex[list1]
<|0.172804 -> {1}, 0.175326 -> {5}, 0.17098 -> {6}, 0.172789 -> {7}, 
 0.173099 -> {8}, 0.190308 -> {10}|>

KeySelect[criterion2] @ PositionIndex[list2]
<|0.173863 -> {1}, 0.143799 -> {9}, 0.181231 -> {10}|>
$\endgroup$
  • $\begingroup$ Dear kglr thank you for your quick response. This is a really nice solution! Do you have any idea, how can I also find the positions in lists1 and 2 of each element that is appented in the joint list? $\endgroup$ – Smaug Jun 17 '20 at 9:50
  • $\begingroup$ @Smaug, please see the update. $\endgroup$ – kglr Jun 17 '20 at 9:55
  • 1
    $\begingroup$ Thank you very much for your time. This is exactly what I was looking for! :D $\endgroup$ – Smaug Jun 17 '20 at 9:58

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.