TransWikia.com

Selecting parts of 2d array based on x value

Mathematica Asked on January 27, 2021

Given a 2d array such as x={{1,2},{2,3},{3,4},{4,5},{5,6}} how would I extract all pairs where the first value is between 2 and 4 such that xpart={{2,3},{3,4},{4,5}}? I need to do this for a very large data set based on different x value constraints, 2 and 4 are just simplified expression.

One Answer

x = {{1, 2}, {2, 3}, {3, 4}, {4, 5}, {5, 6}}
x // Select[Between[First@#, {2, 4}] &]

(* {{2, 3}, {3, 4}, {4, 5}} *)

Correct answer by Rohit Namjoshi on January 27, 2021

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP