7
votes
How to find the nearest element that is bigger than x?
Nearest will either give us the value we're looking for or the value to the left in a sorted list.
So we can simply find the ...
5
votes
Prepend a column of data to a given list
Using the level argument of Join
Join[List /@ Range[0.1, 1, 0.1], data, 2]
gives the expected result:
...
5
votes
How to find the nearest element that is bigger than x?
If unsorted, then a straightforward procedural routine might be good:
...
4
votes
How to replace an element in a list based on the value of the next element?
Using SequenceReplace
list = {0, 0, 0, -1, 0};
SequenceReplace[list, {0, -1} :> Splice @ {1, -1}]
{0, 0, 1, -1, 0}
...
4
votes
How to copy with the last 1 with pattern matching method in a list?
list = {1, 2, 3, 1, 5, 8, 1, 9, 6};
Using SequenceReplace and its 3rd argument
To replace from the end we have to ...
4
votes
How do you efficiently return all of a list but one element?
An update from v13.1 worth adding here is DeleteElements
With a list
list = RandomInteger[{-1, 11}, 13]
...
4
votes
Getting rid of complex numbers in a solution list
RealValuedNumberQ, which came with V 13.3, is custom-tailored for this task:
...
3
votes
How to copy with the last 1 with pattern matching method in a list?
list = {1, 2, 3, 1, 5, 8, 1, 9, 6}
Using FirstPosition:
...
3
votes
3
votes
How to make a pattern to match?
Using Michael's data:
list = {{3, 5, 7, 5, 2}, {1, 2, 3, 4, 5}, {1, 3, 4, 5}, {1, 3, 3}};
Function definition
...
3
votes
Measuring multiple incidences of a continuous constant in a list
Using SequenceSplit (new in 11.3)
list = {{0}, {1}, {1}, {0}, {1}, {0}};
Length /@ SequenceSplit[list, {{0}}]
{2, 1}
3
votes
Adding 1 to all second elements
Supporting @eldo in an effort of good house maintenance as much as I can.
We can use Query
...
3
votes
Adding 1 to all second elements
Showing some of the newer functions
list = {{{5, 1}}, {{2, 1}, {3, 1}}, {{7, 1}}, {{2, 3}}};
1.
ReplaceAt (new in 13.1)
...
3
votes
3
votes
Prepend a column of data to a given list
data= {{3, 4}, {5, 1}, {5, 2}, {1, 8}, {9, 5}, {7, 6}, {25, 15},
{1, 2}, {55, 0}, {10, 1}};
...
3
votes
Translate selection from one list to another
KeySelect is another possibility
al = {1, 2, 3, 4, 5, 6};
bl = {a, b, c, d, e, f};
KeySelect[EvenQ] @ Thread[al -> bl]
<...
2
votes
How to replace an element in a list based on the value of the next element?
Using ReplacePart and Position:
...
2
votes
How to replace an element in a list based on the value of the next element?
We can, also, use SequencePosition+ReplaceAt
...
2
votes
Splitting up delimited data in lists
list = {"section 1", "a", "b", "c", "section 2", "d", "e", "f"};
A slot-free ...
2
votes
How do you efficiently return all of a list but one element?
list = {3, 6, 9, 12, 6};
There are, of course, many more possibilities. Some of them are:
Operator form of DeleteCases
...
2
votes
Prepend 0 to sublists
It's a bit strange for me that no answer used Riffle
With
list = RandomInteger[{1, 9}, {4, 5}];
zero = 0~ConstantArray~{Length@list};
we do:
...
2
votes
2
votes
2
votes
2
votes
2
votes
Max function used with nested lists
list = {{{1, 5, 6}, {4, 7, 8}}, {{1, 2, 2}, {5, 6, 7}}};
1.
With ArrayReduce (new in 12.2)
...
2
votes
2
votes
Measuring multiple incidences of a continuous constant in a list
Since @eldo and @E. Chan-López revived this thread a very small contribution to their efforts.
list = {{0}, {1}, {1}, {0}, {1}, {0}};
then
...
2
votes
Measuring multiple incidences of a continuous constant in a list
Using SplitBy and DeleteCases:
...
2
votes
Only top scored, non community-wiki answers of a minimum length are eligible
Related Tags
list-manipulation × 9406plotting × 826
matrix × 771
performance-tuning × 534
functions × 438
filtering × 420
replacement × 286
pattern-matching × 272
function-construction × 264
string-manipulation × 225
programming × 207
data × 201
equation-solving × 195
map × 186
sorting × 167
graphics × 158
import × 145
combinatorics × 134
functional-style × 122
export × 121
associations × 118
differential-equations × 114
output-formatting × 111
manipulate × 107
conditional × 107