Services & Resources / Wolfram Forums / MathGroup Archive

MathGroup Archive 2012

[Date Index] [Thread Index] [Author Index]

Search the Archive

Re: Transforming/expanding a list

  • To: mathgroup at
  • Subject: [mg127978] Re: Transforming/expanding a list
  • From: Ray Koopman <koopman at>
  • Date: Fri, 7 Sep 2012 04:54:29 -0400 (EDT)
  • Delivered-to:
  • Delivered-to:
  • Delivered-to:
  • Delivered-to:
  • References: <k29m0t$a8r$>

On Sep 6, 1:15 am, Mark Coleman <markspcole... at> wrote:
> I'm working on some Mathematica code that will help transform a large set of lists drawn from my company's legacy database systems. A typical row of the raw data looks like
> The lists are sequences of real numbers, separating some some number of Strings which for convenicence sake we call "NULL" (as opposed to a proper Mathematica Null). The goal is to create a new list where each NULL is replaced by the real number that most recently proceeds it (note that any number of NULLs may occur before or after any real values). I would like the code to return
> {x1,x1,x1,x2,x2,x2,x2,x2,x3,x3,x3,x4,x5,x5}
> Thanks
> Mark


x = x0 (* just in case the first element in data is NULL *);
If[# === NULL, x, x = #]& /@ data

{x1, x1, x1, x2, x2, x2, x2, x2, x3, x3, x3, x4, x5, x5}

  • Prev by Date: Re: Transforming/expanding a list
  • Next by Date: Series expansion of Lambert series
  • Previous by thread: Re: Transforming/expanding a list
  • Next by thread: Re: Transforming/expanding a list