Can someone suggest how a pattern would be constructed to extract the first list of contiguous numbers from this data?
sample = {52.2624, 54.4003, 60.7418, 61.3801, 62.6397, 61.7992,
63.2282, "", "", "", "", "", "", "", "", "", "", 62.3921, 61.897,
60.299, 59.053, 61.3778, 64.3724, 63.4251, 78.1912, 79.7451,
80.4741, "", 81.324, 79.9114, 93.7509};
I have tried variations like sample //. {useable : _?NumberQ .., ___} -> {useable}
to no avail.
useable = TakeWhile[sample, NumberQ]
works well, but I would like to know how to do it using pattern matching.
Most repeating patterns in the environment occur in manufactured objects. Some examples are tiles, pavers, windows, zebra crossings and railway lines. Such objects are generally assembled from units that are very nearly identical.
A pattern is a design in which lines, shapes, forms or colours are repeated. The part that is repeated is called a motif. Patterns can be regular or irregular. Art and Design.
Trying to preserve your logic:
sample /. {useable : Longest[_?NumberQ ..], ___} -> {useable}
If you want the longest numeric sequence:
sample /. {___, useable : Longest[_?NumberQ ..], ___} -> {useable}
Edit
To get all the numeric sequences:
Cases[SplitBy[sample, NumberQ], {_?NumberQ ..}]
or
Last@Reap[sample //. {x___, useable : Longest[_?NumberQ ..], y___} :>
(Sow@{useable}; {x}~Join~{y})]
One way would be
sample /. {Longest[useable___?NumberQ], ___} :> {useable}
which returns {52.2624, 54.4003, 60.7418, 61.3801, 62.6397, 61.7992, 63.2282}
from your sample.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With