Mathematica 9 is now available
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 smc.vnet.net
  • Subject: [mg127983] Re: Transforming/expanding a list
  • From: Murta <rodrigomurtax at gmail.com>
  • Date: Fri, 7 Sep 2012 04:56:09 -0400 (EDT)
  • Delivered-to: l-mathgroup@mail-archive0.wolfram.com
  • Delivered-to: l-mathgroup@wolfram.com
  • Delivered-to: mathgroup-newout@smc.vnet.net
  • Delivered-to: mathgroup-newsend@smc.vnet.net
  • References: <k29m0t$a8r$1@smc.vnet.net>

Hi Mark
There is one suggenstion

data={"x1",Null,Null,"x2",Null,Null,Null,Null,"x3",Null,Null,"x4","x5",Null}

ConstantArray[#[[1]],Length[#]]&/@Split[data,(#2==Null)&]//Flatten

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

best Regards
Murta

On Thursday, September 6, 2012 5:15:28 AM UTC-3, Mark Coleman 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
>
>
>
> {x1,NULL,NULL,x2,NULL,NULL,NULL,NULL,x3,NULL,NULL,x4,x5,NULL} ...
>
>
>
> 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



  • Prev by Date: Re: Clustering
  • Next by Date: Re: A new FrontEnd
  • Previous by thread: Re: Transforming/expanding a list
  • Next by thread: Re: Transforming/expanding a list