If the text is to be converted to numbers anyhow and assuming boxing is
superfluous then, the whole process could be made more efficient in time and
space.

brc1=: 3 : 0
'y s'=. (,;$) >y. 
s $ y=.'.' (I. y  e. ',') } y
)

   ts '".&> rplccomma &.> A'
0.12046081 879680
   ts '".&> brc A'
0.044780995 1273344
   ts '".brc1 A'
0.032958791 723456


R.E. Boss



-----Oorspronkelijk bericht-----
>Van: [EMAIL PROTECTED]
[mailto:[EMAIL PROTECTED] Namens Chris Burke
>Onderwerp: Re: [Jprogramming] Faster way to replace commas in boxed data
>
>Anssi Seppälä wrote:
>> Reading numeric data from Excel the decimal separator is here comma " ,
>> ". Since in  J the text-to-num-conversion function  ".  does not
>> understand comma as decimal separator I must change the commas in the
>> boxed matrix DATA to dots. I could write a short function:
>> 
>> rplccomma=: 3 : '''.'' (I. y.  e. '','')} y.'
>> 
>> and then run
>> 
>> NUM= . ". each rplccomma each DATA.
>> 
>> For large DATA this takes long time to run. Ideas to make this
>> conversion faster are wellcome. Thanks.
>
>For long boxed lists, it is often quicker to work on the razed list. For
>example:
>
>brc=: 3 : 0
>y=. ; y. ,each {:a.
>($y.) $ < ;._2 '.' (I. y  e. ',') } y
>)
>
>   A=: 10000 $ '123,45';'1234,56'
>
>   (brc A) -: rplccomma each A
>1
>   timex 'brc A'
>0.026006
>   timex 'rplccomma each A'
>0.141489
>

----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm

Reply via email to