# Questions tagged [list-manipulation]

Questions on the manipulation of List objects in Mathematica, and the functions used for these manipulations.

6,776 questions
Filter by
Sorted by
Tagged with
919 views

### How can I remove B -> A from a list if A -> B is in the list?

I have a list of transformations like this: list = {"A" -> "B", "B" -> "A", "C" -> "D"} As this is used to plot an undirected graph with ...
330 views

### Check in a series if there exists adjacent values with less than a certain number of missing values

I'm working with a large number of series of different experiments, where there exist a lot of experiments where there are no entries. I now want to draw a sample where there should exist at least ...
12k views

### How to Delete Elements from List1 appearing in List2?

I'm new to functional programming of Mathematica and trying to remove one list of assorted elements from another. However I only find functions working with the Index rather than the values itself: ...
2k views

### Permutations[Range[12]] produces an error instead of a list

This input: Permutations[Range[12]] Results in this (error) output: ...
2k views

### Selectively Mapping over elements in a List

I am using the following code to easily generate a row of images of all eight planets of our Solar System: ...
200 views

### Bug in LengthWhile?

Bug introduced in 8.0.0 and fixed in 8.0.1 Is this a bug or my MMA went insane or I'm missing something? LengthWhile[Reverse@IntegerDigits[1000], # == 0 &] ...
3k views

### Efficient way to count the number of zeros at the (right) end of a very large number

If I want to count the number of zeros at the (right) end of a large number, like $12345!$, I can use something like: Length[Last[Split[IntegerDigits[12345!]]]] ...
2k views

### On generalizing Partition[] (with offsets) to sublists of unequal length

The usual Partition[] function is a very handy little thing: ...
12k views

### Creating a data1 versus data2 plot?

I have a table of data with multiple rows and columns, and I have to make a versus data table using two of these columns. Essentially, I have to set one column of data (column 3) as the y-axis and ...
4k views

### Combination and Permutation

How could I obtain the list of all the groups of 5 numbers taken from Range[12] such that the 2 lists have an empty intersection : ...
3k views

### Finding a subsequence in a list

I have a list and I want to find (in this particular case the first) appearance of a any of some subsequences, of possible different lengths. None of the subsequences is a subsequence of each other. ...
5k views

### How to find rows that have maximum value?

Suppose if I have following list { {10,b,30}, {100,a,40}, {1000,b,10}, {1000,b,70}, {100,b,20}, {10,b,70} } How to find rows that have max value in ...
4k views

### Flatten at a certain level

In an earlier question the brainteasing fourth syntax variant of Flatten was discussed. I see that with ...
4k views

### Why don't * and ^ work as I expected on matrices? [closed]

For example, this input... {{1, 2}, {3, 4}}*{{1, 2}, {3, 4}} produces this output... {{1, 4}, {9, 16}} and this input... <...
401 views

### Unexpected behavior from GatherBy in version 7

Bug introduced in 7.0 or earlier and fixed in 8.0.4 or earlier I have come across what appears to be a bug in GatherBy. It appears similar to the problem of using ...
513 views

### How to generate Intervals from a given list?

If I have a list list={3,7,4,5,1} how to get the List of Intervals /Ranges result = {{1,3},{3,4},{4,5},{5,7}}
2k views

### How to find range in which a number falls, from given list of numbers?

How can one find the range in which a number falls, from given list of numbers? ...
877 views

### Elegantly pairing up mismatched lists

HistogramList returns a list of bin boundaries and a list of counts. There is one more boundary than counts, and I'd like to pair them up so I can feed it into <...
2k views

### Efficient way to combine SparseArray objects?

I have several SparseArray objects, say sa11, sa12, sa21, sa22, which I would like to combine into the equivalent of {{sa11, sa12}, {sa21, sa22}}. As an example, I ...
19k views

### What is the most efficient way to add rows and columns to a matrix?

Say I have a matrix m and a vector v. ...
55k views

### How to find the position of elements in a list satisfying criteria

Say I have a list x={2,4,6,8,10} and I want to find out the positions of the elements that are greater than 7. ...
2k views

### How do you efficiently return all of a List but one element?

I have a problem that I am working on that requires that I compare several lists of overlapping data points. As I traverse one of the lists, I'd like to only compare those data to the other lists, and ...
5k views

### Flatten command: matrix as second argument

One thing I could never wrap my head around is how Flatten works when provided with a matrix as the second argument, and the Mathematica help isn't particularly ...
2k views

### How to use Union on list of lists without sorting them first?

If I do ClearAll[a, d] lsts = {{a, d}, {a, d}}; Union[lsts] I get the expected answer {{a, d}} but if I do ...
1k views

### Data Table Manipulation in Mathematica: Step 2

In this previous post (Data Table Manipulation in Mathematica) we find the brilliant suggestion proposed by Leonid Shifrin that allows to select specific rows identified by the header name. I'm now ...