All Questions

Filter by
Sorted by
Tagged with
1
vote
0answers
28 views

Replacing factors that are only dependent on a single specific variable

I have expressions with terms that are products of factors. Some of the factors are expressions that depend on a single specific variable. I would like to replace those factors with constants and ...
7
votes
3answers
147 views

Creating rule-based sublists

I have a list each element of which consists of a list containing two strings and two integers: ...
3
votes
3answers
98 views

Find element in a list matching a pattern (using wildcards)

Somehow, I did not manage to find anything related to that. Suppose, in my Global list of variables, I would like to make a search such that I obtain all the ...
4
votes
0answers
66 views

Why does Shortest not work inside SequencePosition?

Why does Shortest not work in a SequencePosition call? The following two commands return the same answer: ...
3
votes
2answers
80 views

Using DeleteCases with a defined function with two arguments as a pattern

I am trying to manipulate some large datasets in Mathematica. I have plotted the data, and I would like to be able to easily remove points from the dataset, and it's fairly easy to identify the x-...
5
votes
2answers
222 views

Manipulating a general length function

As a minimal example, define a function like s[1,2,3]; this is a function of three arguments in this case, but I'd like to apply this general idea to functions like ...
3
votes
2answers
65 views

Dropping lists using pattern [duplicate]

I have the following list of lists. data = {{0, 0, 0}, {1, 0, 0}, {2, 0, 1}, {3, 0, 0}, {4, 0, 0}, {5, 0, 3}} I want to drop all the lists with ...
1
vote
1answer
28 views

Splitting a list of letters into subsequences starting with uppercase letters [duplicate]

Given a list of upper/lowercase characters, I'm trying to split it into subsequences that start with an uppercase and contain the next few (not necessarily positive number of) elements up until the ...
6
votes
1answer
129 views

Cases, Pattern, Condition [duplicate]

I supposed Cases would do the list produced as example li = RandomSample[Range[100, 999], 30] ...
2
votes
1answer
36 views

Reformatting the pattern inside a list

So, in principle, I have a simple problem which goes like this: I have vectors that should consist of lists of 2 numbers, see here: ...
3
votes
1answer
52 views

How can I replace non-reals in a multidimensional list?

Ok. I'm obviously not understanding something about pattern matching. I have a list called t like the following: ...
13
votes
3answers
429 views

Generating a pattern from user-defined rules

I want to generate a list of $L$ and $S$ according to the following rule: upon each iteration, replace $S \rightarrow L$ $L \rightarrow LS$ Such that, starting with $L$: $ L \rightarrow LS \...
9
votes
2answers
171 views

Find pattern with Position

I have a list a = {L, S, L, L, S} and I can find the position of of either L or S by: ...
2
votes
0answers
48 views

Why do I get this warning when replacing pattern with list element? [closed]

The input x^2 + x^3 /. x^i_ -> i yields: 5 The input u = {1, 2, 3} x^2 + x^3 /. x^i_ -> u[[i]] still yields the ...
10
votes
4answers
425 views

Making a list of patterns of arbitrary length

I would like to create a list of arbitrary length: {x1_, x2_, ...} Where each of the elements of the list has the full form: ...
4
votes
2answers
168 views

Pattern matching list of lists containing only numbers

I'm trying to define a pattern that will match lists of lists, where the inner lists contains only numbers (I want the sum of each list). Like this ...
2
votes
1answer
72 views

How to use `Pattern` and `Slot` to match n-element conditions?

Extract the qualifying sublists. – Condition: The elements are all in the Reals and greater than zero. Question If the sublist contains many elements, how can it ...
2
votes
1answer
88 views

DeleteCases not working as expected

I am trying to reproduce the example of Data Cleaning from here. I had to make a slight change in input 13 to ...
3
votes
3answers
230 views

How to take a part from a list without evaluating it

Consider I have a list l ...
6
votes
3answers
457 views

Put edges of a matrix to zero

I have to set the first and last rows and columns to zero rows and columns. I tried with the first column: ...
3
votes
3answers
179 views

A pattern condition involving OrderedQ

I have the following simple code: z = {a, b, c} {{1, 2, 3}, {1, 3, 2}, {3, 2, 1}} /. {a_Integer, b_Integer, c_Integer} /; OrderedQ[z] -> 1 which returns ...
2
votes
2answers
119 views

Totally orderless partition

This is a slight variation of: How to generate all possible orderless partitions of a list according to another list? Consider each set following a partition a "box" and each element a "ball". What ...
2
votes
3answers
118 views

Checking if a list of length $n$ has pairs?

I have a list of reals and I want to check if for every element $i$ there is another element $j$ such that $\lvert{i-j}\rvert \leq x$ where $x$ is some arbitrary value. Each element can only be "...
0
votes
1answer
97 views

How to use Pattern matching to get the right hand side of a rule?

I have a List that looks as follows: ...
3
votes
1answer
117 views

Find elements of a list matching specific patterns

I have defined several symbolic function f[x],g[x,y],h[x,y,z] etc... And I have a list made of elements which are product of these functions with different ...
2
votes
2answers
101 views

How to find the frequency of a pattern in a list?

Consider a list (list) as list = {{0, 0, 0, 1, 2}, {1, 1, 0, 1, 1}, {2, 2, 1, 0, 0}, {1, 1, 0, 2, 0}, {0, 0, 1, 0, 1}}; ...
11
votes
1answer
171 views

Problem with DeleteCases

I'm about to report this as a bug but wondered what you would make of it. Works as expected in version 7. ...
2
votes
1answer
131 views

Differences between Cases and Position [duplicate]

I'm having trouble understanding the difference between Cases and Position. What I want to do is to identify the elements of a ...
3
votes
3answers
63 views

duplicating entry values of a list to match varying size of entrys in another list

let's say I have a list of lists that looks like abc={{1,{{1},{2}}},{2,{{3},{4},{5}}},{3,{{2}}}}//TableForm, where the first entry in every row, the one ...
5
votes
1answer
85 views

Counting subsequences matching a pattern

Given a sequence $(a_1, a_2, \ldots, a_n)$ and a number $m$, I'd like to count the number of subsequences $(a_{i_1},a_{i_2},a_{i_3})$ such that $a_{i_2} < m \leq a_{i_1}, a_{i_3}$. For example, if ...
4
votes
3answers
425 views

Deleting certain elements of a list

This query is similar to a question I posted earlier. Given testList = {{"a", "b 3", "cd", "ef 23"}, {"z 12", "y", "x"}, {"z", "y"}, {"a", "b3"}}; I would ...
2
votes
1answer
74 views

Recognize list structure

Suppose I have several lists: ...
3
votes
3answers
132 views

Understanding PatternTest inside Position

I have a list of n dimensional vectors (n=3 in this example). I want to find the position of all vectors for which all elements other than the $i^{th}$ element are equal to some value (2 in this ...
0
votes
2answers
271 views

Dataset, use list as header

I have a dataset with a header for row and column which consists of binaries, e.g.: ...
3
votes
4answers
186 views

Listing all distinct exhaustive combinations of sublists of a certain length [duplicate]

I would like to do the following: Suppose there is a list {a, b, c, d}. I would like to get all distinct exhaustive combinations of its sublists of a certain ...
3
votes
2answers
76 views

Isolate first order elements

How can I isolate only the first order "h" terms in the following expression? ...
7
votes
3answers
290 views

Can logical operators be used with Cases?

Suppose I want all two digit primes between -75 and 100 inclusive. a=Range[-75,100] Select[Select[Cases[a, ?_Positive],(#>9&)],PrimeQ] does it, but can'...
3
votes
3answers
563 views

Split list based on positions contained in another list

The problem Suppose that after importing several files into my nb (x-y dataset, but this procedure should work also for x-y-z datasets), I end up with a nested list similar to: ...
5
votes
2answers
372 views

Delete elements from a list with consecutive elements in sublist

I do not know if this is question has already been asked but I did see some posts on deleting duplicate elements but I am unable to understand completely. So forgive me if this turns out to be ...
4
votes
2answers
103 views

Select Consecutive Association rows based on pattern

I have an association that I have already sorted on "EVDATE" and then grouped by some Keys. In this case "CONTID" and ...
6
votes
4answers
318 views

How to repeat the nonblank string?

As the title, if I have a list: {"", "", "", "2$70", ""} I will expect: {"", "", "", "2$70", "2$70"} If I have ...
3
votes
1answer
107 views

How do I find and highlight the elements of a list that match a specific pattern?

I have a list of positive and negative ones {1,1,-1,1,1,-1,1,-1,1,-1,-1,1,1,1,-1} And I want to find and highlight the subsequence of the lists that have the pattern {...,1,1,___,-1,-1,...}. So ...
4
votes
1answer
81 views

Creating a dataset by matching one dataset to another

I have a dataset as a list paired terms {fruit1,fruit2}: Example: ...
3
votes
1answer
83 views

Repeated consecutive values above a threshold

I would like to know if a list has repeated consecutive values above a threshold. Lets say for this example the threshold is 5. ...
1
vote
1answer
57 views

How to match the iterative head in a iterative list

I want to delete the f[g[...]] last appear in a iterative list.Such as: ...
4
votes
3answers
246 views

How to copy with the last 1 with pattern matching method in a list

Suppose I have a list like {1, 2, 3, 1, 5, 8, 1, 9, 6} The {1, 2, 3, 1, 5, 8, 9, 6} is expected. Furthermore, if we want to ...
4
votes
5answers
300 views

Find the length of repeating numbers in a list

a = 4; primes = Prime[Range[PrimePi[10^(a - 1)] + 1, PrimePi[10^a]]]; d = 1; Cases[IntegerDigits[primes], {_, d .., _}] This gets me the list of the numbers from ...
5
votes
3answers
547 views

How to make a pattern to match?

Consider DeleteCases[{{1, 2, 3, 4}, {1, 3, 4, 5}}, {_, 3, __}] {{1, 2, 3, 4}} i.e., keep only those lists that don't have 3...
4
votes
0answers
82 views

`Optional` with non-empty list requires PatternTest/Condition?

Arbitrary lists are easy to use with Optional: a[0]~MatchQ~a[0, Optional[x_List, {}]] a[0]~MatchQ~a[0, Optional[x:{___}, {}]] ...
8
votes
3answers
213 views

Prevent testing Head with ReplaceAll

I have a list of strings list. I am trying to get rid of some elements that match string pattern patt: ...