问题
I have imported some data into Mathematica. The data will look similar to
{{0,2},{2,3},{4,3},{5,4},{8,4}}
I want to throw out all elements for which the x-values are smaller than a given value or create a new list that contains the data for which the x-values are larger than this value. I assume that Select should do the job but I don't know how.
Thanks in advance for the help.
回答1:
How about
data = {{0,2},{2,3},{4,3},{5,4},{8,4}};
filtered = Select[data, First[#]>3&];
where you replace 3 with your given value?
回答2:
Another versatile approach is to use Cases and attach a condition (/;)
For example:
data = {{0, 2}, {2, 3}, {4, 3}, {5, 4}, {8, 4}}; Cases[data, {x_, y_} /; x > 3]
or attach a condition as follows (for example):
Cases[data, {x_ /; x > 3, _}]
(The approach will also work with DeleteCases)
来源:https://stackoverflow.com/questions/4118474/manipulate-list-in-mathematica-with-select