<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic How to convert a numeric list into a character one? in Discussions</title>
    <link>https://community.jmp.com/t5/Discussions/How-to-convert-a-numeric-list-into-a-character-one/m-p/378147#M62792</link>
    <description>&lt;P&gt;Hi everybody,&lt;/P&gt;&lt;P&gt;I have a list containing numbers and I would like to transform them into characters. Is there a way to do that without using a loop? I was not able to find the proper function.&lt;/P&gt;&lt;P&gt;Thanks for your help!&lt;/P&gt;</description>
    <pubDate>Fri, 09 Jun 2023 22:11:31 GMT</pubDate>
    <dc:creator>anne_sa</dc:creator>
    <dc:date>2023-06-09T22:11:31Z</dc:date>
    <item>
      <title>How to convert a numeric list into a character one?</title>
      <link>https://community.jmp.com/t5/Discussions/How-to-convert-a-numeric-list-into-a-character-one/m-p/378147#M62792</link>
      <description>&lt;P&gt;Hi everybody,&lt;/P&gt;&lt;P&gt;I have a list containing numbers and I would like to transform them into characters. Is there a way to do that without using a loop? I was not able to find the proper function.&lt;/P&gt;&lt;P&gt;Thanks for your help!&lt;/P&gt;</description>
      <pubDate>Fri, 09 Jun 2023 22:11:31 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/How-to-convert-a-numeric-list-into-a-character-one/m-p/378147#M62792</guid>
      <dc:creator>anne_sa</dc:creator>
      <dc:date>2023-06-09T22:11:31Z</dc:date>
    </item>
    <item>
      <title>Re: How to convert a numeric list into a character one?</title>
      <link>https://community.jmp.com/t5/Discussions/How-to-convert-a-numeric-list-into-a-character-one/m-p/378193#M62794</link>
      <description>&lt;P&gt;Here is a little script that creates a function that does what you want.&amp;nbsp; You can either define and use the function in your code, or use the 4 statements in open code to do the conversion.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;Names Default To Here( 1 );
theList = {7,8,9};

NumListToChar = Function( {myList},
	{defaultlocal},
	dtx = New Table( "x", New Column( "y", values( myList ) ), private );
	dtx:y &amp;lt;&amp;lt; data type( character );
	myList = dtx:y &amp;lt;&amp;lt; get values;
	Close( dtx, nosave );
	Return( myList );
);

theList = NumListToChar( theList );&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 20 Apr 2021 11:52:59 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/How-to-convert-a-numeric-list-into-a-character-one/m-p/378193#M62794</guid>
      <dc:creator>txnelson</dc:creator>
      <dc:date>2021-04-20T11:52:59Z</dc:date>
    </item>
    <item>
      <title>Re: How to convert a numeric list into a character one?</title>
      <link>https://community.jmp.com/t5/Discussions/How-to-convert-a-numeric-list-into-a-character-one/m-p/378220#M62797</link>
      <description>&lt;P&gt;Thanks for your answer &lt;a href="https://community.jmp.com/t5/user/viewprofilepage/user-id/2687"&gt;@txnelson&lt;/a&gt; it is indeed what I was looking for.&lt;/P&gt;&lt;P&gt;I just wonder what is the faster between a loop and a function which involves table creation. Any idea?&lt;/P&gt;</description>
      <pubDate>Tue, 20 Apr 2021 12:22:07 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/How-to-convert-a-numeric-list-into-a-character-one/m-p/378220#M62797</guid>
      <dc:creator>anne_sa</dc:creator>
      <dc:date>2021-04-20T12:22:07Z</dc:date>
    </item>
    <item>
      <title>Re: How to convert a numeric list into a character one?</title>
      <link>https://community.jmp.com/t5/Discussions/How-to-convert-a-numeric-list-into-a-character-one/m-p/378237#M62799</link>
      <description>&lt;P&gt;New in JMP 16 is the &lt;A href="https://www.jmp.com/support/help/en/16.0/#page/jmp/conditional-and-logical-functions.shtml#ww10169967" target="_self"&gt;For Each() function&lt;/A&gt; which iterates over a container – list, matrix, or associative array – to perform an operation on each element.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Here is an example to show how to use it to convert your list of numbers to a list of character strings.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;Names Default To Here( 1 );
theList = {7, 8, 9};

For Each( {value, index}, theList, theList[index] = Char( value ) );&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 20 Apr 2021 12:35:44 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/How-to-convert-a-numeric-list-into-a-character-one/m-p/378237#M62799</guid>
      <dc:creator>Jeff_Perkinson</dc:creator>
      <dc:date>2021-04-20T12:35:44Z</dc:date>
    </item>
    <item>
      <title>Re: How to convert a numeric list into a character one?</title>
      <link>https://community.jmp.com/t5/Discussions/How-to-convert-a-numeric-list-into-a-character-one/m-p/378256#M62802</link>
      <description>&lt;P&gt;Thanks &lt;a href="https://community.jmp.com/t5/user/viewprofilepage/user-id/6878"&gt;@Jeff_Perkinson&lt;/a&gt; !&lt;/P&gt;&lt;P&gt;I did some simulations just by curiosity to compare the execution time of each solution and it seems that the for each function is on average the fastest one!&lt;/P&gt;&lt;P&gt;So I am gonna pick that one although the function of &lt;a href="https://community.jmp.com/t5/user/viewprofilepage/user-id/2687"&gt;@txnelson&lt;/a&gt; also works very well.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks to both of you :)&lt;/img&gt;&lt;/P&gt;</description>
      <pubDate>Tue, 20 Apr 2021 12:57:53 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/How-to-convert-a-numeric-list-into-a-character-one/m-p/378256#M62802</guid>
      <dc:creator>anne_sa</dc:creator>
      <dc:date>2021-04-20T12:57:53Z</dc:date>
    </item>
    <item>
      <title>Re: How to convert a numeric list into a character one?</title>
      <link>https://community.jmp.com/t5/Discussions/How-to-convert-a-numeric-list-into-a-character-one/m-p/378258#M62804</link>
      <description>&lt;P&gt;Here's a quick timing program for the three methods, for loop, for each, and custom function using data table.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;Names Default To Here( 1 );

listsize=1000000;

theList = As List( J( listsize, 1, Random Integer( 100 ) ) );

NumListToChar = Function( {myList},
	{defaultlocal},
	dtx = New Table( "x", New Column( "y", values( myList ) ), private );
	dtx:y &amp;lt;&amp;lt; data type( character );
	myList = dtx:y &amp;lt;&amp;lt; get values;
	Close( dtx, nosave );
	Return( myList );
);

start = HP Time();
For Each( {value, index}, theList, theList[index] = Char( value ) );
foreachloop = HP Time() - start;

theList = As List( J( listsize, 1, Random Integer( 100 ) ) );

start = HP Time();
theList = NumListToChar( theList );
customfunction = HP Time() - start;

theList = As List( J( listsize, 1, Random Integer( 100 ) ) );

start = HP Time();
For( i = 1, i &amp;lt;= N Items( theList ), i++,
	theList[i] = Char( theList[i] )
);
forloop = HP Time() - start;

show(foreachloop, customfunction, forloop);&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;For me with the listsize shown above the results are very similar between the three methods:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;foreachloop = 1106974;
customfunction = 1077862;
forloop = 1400643;
&lt;/PRE&gt;</description>
      <pubDate>Tue, 20 Apr 2021 12:59:57 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/How-to-convert-a-numeric-list-into-a-character-one/m-p/378258#M62804</guid>
      <dc:creator>Jeff_Perkinson</dc:creator>
      <dc:date>2021-04-20T12:59:57Z</dc:date>
    </item>
    <item>
      <title>Re: How to convert a numeric list into a character one?</title>
      <link>https://community.jmp.com/t5/Discussions/How-to-convert-a-numeric-list-into-a-character-one/m-p/378296#M62809</link>
      <description>&lt;P&gt;Extending Jeff's answer&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Different overheads hurt for small sizes and help for large sizes." style="width: 545px;"&gt;&lt;img src="https://community.jmp.com/t5/image/serverpage/image-id/32211iC919E0B39F5889E2/image-size/large?v=v2&amp;amp;px=999" role="button" title="Capture.PNG" alt="Different overheads hurt for small sizes and help for large sizes." /&gt;&lt;span class="lia-inline-image-caption" onclick="event.preventDefault();"&gt;Different overheads hurt for small sizes and help for large sizes.&lt;/span&gt;&lt;/span&gt;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;dt = New Table( "Untitled 3",
	Add Rows( 0 ),
	New Column( "size", Numeric, "Continuous", Format( "Best", 12 ), Set Values( [] ) ),
	New Column( "for", Numeric, "Continuous", Format( "Best", 12 ), Set Values( [] ) ),
	New Column( "foreach", Numeric, "Continuous", Format( "Best", 12 ), Set Values( [] ) ),
	New Column( "custom", Numeric, "Continuous", Format( "Best", 12 ), Set Values( [] ) )
);

NumListToChar = Function( {myList},
	{defaultlocal},
	dtx = New Table( "x", New Column( "y", values( myList ) ), private );
	dtx:y &amp;lt;&amp;lt; data type( character );
	myList = dtx:y &amp;lt;&amp;lt; get values;
	Close( dtx, nosave );
	Return( myList );
);

For( listsize = 1, listsize &amp;lt; 1e7, listsize *= 2, 

	theList = As List( J( listsize, 1, Random Integer( 100 ) ) );

	start = HP Time();
	For Each( {value, index}, theList, theList[index] = Char( value ) );
	foreachloop = HP Time() - start;

	theList = As List( J( listsize, 1, Random Integer( 100 ) ) );

	start = HP Time();
	theList = NumListToChar( theList );
	customfunction = HP Time() - start;

	theList = As List( J( listsize, 1, Random Integer( 100 ) ) );

	start = HP Time();
	For( i = 1, i &amp;lt;= N Items( theList ), i++,
		theList[i] = Char( theList[i] )
	);
	forloop = HP Time() - start;

	Show( foreachloop, customfunction, forloop );
	dt &amp;lt;&amp;lt; addrows( 1 );
	dt:size[N Rows( dt )] = listsize;
	dt:for[N Rows( dt )] = forloop / 1e6;
	dt:foreach[N Rows( dt )] = foreachloop / 1e6;
	dt:custom[N Rows( dt )] = customfunction / 1e6;
	Wait( 0.1 ); // so it shows on display
);&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 20 Apr 2021 13:36:59 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/How-to-convert-a-numeric-list-into-a-character-one/m-p/378296#M62809</guid>
      <dc:creator>Craige_Hales</dc:creator>
      <dc:date>2021-04-20T13:36:59Z</dc:date>
    </item>
    <item>
      <title>Re: How to convert a numeric list into a character one?</title>
      <link>https://community.jmp.com/t5/Discussions/How-to-convert-a-numeric-list-into-a-character-one/m-p/378301#M62810</link>
      <description>&lt;P&gt;Thanks for the additional information &lt;a href="https://community.jmp.com/t5/user/viewprofilepage/user-id/6878"&gt;@Jeff_Perkinson&lt;/a&gt; and &lt;a href="https://community.jmp.com/t5/user/viewprofilepage/user-id/982"&gt;@Craige_Hales&lt;/a&gt; !&lt;/P&gt;&lt;P&gt;We always learn a lot of things with the Community!!&lt;/P&gt;</description>
      <pubDate>Tue, 20 Apr 2021 13:49:35 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/How-to-convert-a-numeric-list-into-a-character-one/m-p/378301#M62810</guid>
      <dc:creator>anne_sa</dc:creator>
      <dc:date>2021-04-20T13:49:35Z</dc:date>
    </item>
    <item>
      <title>Re: How to convert a numeric list into a character one?</title>
      <link>https://community.jmp.com/t5/Discussions/How-to-convert-a-numeric-list-into-a-character-one/m-p/378512#M62826</link>
      <description>&lt;P&gt;Nice illustration of the size-dependent performance of the different functions. I'm still using JMP 15 and can't use&amp;nbsp;&lt;EM&gt;For Each()&lt;/EM&gt; yet, but to extend Jeff's timing exercise further I toss in two more functions that give the same result.&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;Repeat(k = 0; {k++; Char( theList[k] )}, listsize);

Words( Substr( Char( theList ), 2, Length( Char( thelist ) ) - 2 ), ", " );&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="NumtoChar.png" style="width: 999px;"&gt;&lt;img src="https://community.jmp.com/t5/image/serverpage/image-id/32245iAA7A80DBD475FACE/image-size/large?v=v2&amp;amp;px=999" role="button" title="NumtoChar.png" alt="NumtoChar.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;The For loop, which is the fastest for small lists, is surpassed by Words at size&amp;gt;50, by the data-table-detour function at size&amp;gt;1000 and by Repeat at size&amp;gt;30000.&lt;/P&gt;
&lt;P&gt;I was a little surprised to see that Words remained the fastest for size&amp;gt;50, about twice as fast at millions of "words".&lt;/P&gt;</description>
      <pubDate>Wed, 21 Apr 2021 11:18:28 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/How-to-convert-a-numeric-list-into-a-character-one/m-p/378512#M62826</guid>
      <dc:creator>ms</dc:creator>
      <dc:date>2021-04-21T11:18:28Z</dc:date>
    </item>
    <item>
      <title>Re: How to convert a numeric list into a character one?</title>
      <link>https://community.jmp.com/t5/Discussions/How-to-convert-a-numeric-list-into-a-character-one/m-p/378594#M62837</link>
      <description>&lt;P&gt;Wow I was looking for one solution and I got so many! JMP is amazing! Thanks all of you!&lt;/P&gt;</description>
      <pubDate>Wed, 21 Apr 2021 06:42:37 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/How-to-convert-a-numeric-list-into-a-character-one/m-p/378594#M62837</guid>
      <dc:creator>anne_sa</dc:creator>
      <dc:date>2021-04-21T06:42:37Z</dc:date>
    </item>
    <item>
      <title>Re: How to convert a numeric list into a character one?</title>
      <link>https://community.jmp.com/t5/Discussions/How-to-convert-a-numeric-list-into-a-character-one/m-p/378658#M62840</link>
      <description>&lt;P&gt;&lt;a href="https://community.jmp.com/t5/user/viewprofilepage/user-id/5080"&gt;@DonMcCormack&lt;/a&gt;- &lt;A href="https://community.jmp.com/t5/JMP-Challenge/bg-p/jmp-challenge-blog" target="_blank" rel="noopener"&gt;Challenge&lt;/A&gt;!&lt;/P&gt;</description>
      <pubDate>Wed, 21 Apr 2021 11:57:54 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/How-to-convert-a-numeric-list-into-a-character-one/m-p/378658#M62840</guid>
      <dc:creator>Craige_Hales</dc:creator>
      <dc:date>2021-04-21T11:57:54Z</dc:date>
    </item>
    <item>
      <title>Re: How to convert a numeric list into a character one?</title>
      <link>https://community.jmp.com/t5/Discussions/How-to-convert-a-numeric-list-into-a-character-one/m-p/378696#M62850</link>
      <description>&lt;P&gt;Thanks &lt;a href="https://community.jmp.com/t5/user/viewprofilepage/user-id/982"&gt;@Craige_Hales&lt;/a&gt; ! I like it. Let me see if I can work it into the next Challenge. Should we try to avoid any iteration or just &lt;FONT face="courier new,courier"&gt;For&lt;/FONT&gt; (and its derivatives)?&amp;nbsp; One way of avoiding iteration is through expression evaluation. If you're unfamiliar with this approach, check out &lt;a href="https://community.jmp.com/t5/user/viewprofilepage/user-id/78"&gt;@joseph_morgan&lt;/a&gt; 's &lt;A href="https://community.jmp.com/t5/Discovery-Summit-Europe-2017/JSL-Tutorial/ta-p/37472" target="_self"&gt;Discovery tutorial, point 1&lt;/A&gt;. For the above problem, the function might look something like this:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;convertNumberToCharacter = Function({inList},{i=1,outList={}},
	outList[1::N Items(inList)] = Expr(Char(inList[i++]));
	Eval List(outList);
);

/* You can check it out using the code below.
	tStart  = HP Time();
	alist   = As List(J(10000,1,Random Normal(1e6,1e5)));
	newList = convertNumberToCharacter(alist);
	Print((HP Time()-tStart)/1e6);
*/&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;I have tried this in a few of the Challenges and, while succinct, tends to take longer and is harder to understand (unless you are fairly familiar with expression handling).&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 21 Apr 2021 14:06:30 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/How-to-convert-a-numeric-list-into-a-character-one/m-p/378696#M62850</guid>
      <dc:creator>DonMcCormack</dc:creator>
      <dc:date>2021-04-21T14:06:30Z</dc:date>
    </item>
    <item>
      <title>Re: How to convert a numeric list into a character one?</title>
      <link>https://community.jmp.com/t5/Discussions/How-to-convert-a-numeric-list-into-a-character-one/m-p/378747#M62856</link>
      <description>&lt;P&gt;There's also Transform Each, which appears to be a little faster than For Each here.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;	theList = Transform Each( {value}, theList, Char( value ) );
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 21 Apr 2021 16:04:40 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/How-to-convert-a-numeric-list-into-a-character-one/m-p/378747#M62856</guid>
      <dc:creator>XanGregg</dc:creator>
      <dc:date>2021-04-21T16:04:40Z</dc:date>
    </item>
    <item>
      <title>Re: How to convert a numeric list into a character one?</title>
      <link>https://community.jmp.com/t5/Discussions/How-to-convert-a-numeric-list-into-a-character-one/m-p/378752#M62857</link>
      <description>&lt;P&gt;&lt;a href="https://community.jmp.com/t5/user/viewprofilepage/user-id/5080"&gt;@DonMcCormack&lt;/a&gt;&amp;nbsp;The vanilla for-loop is both fastest, and slowest, depending on problem size. I'm &lt;EM&gt;really &lt;/EM&gt;surprised &lt;a href="https://community.jmp.com/t5/user/viewprofilepage/user-id/182"&gt;@ms&lt;/a&gt; the words-based solution performs so well at large sizes. I really like the unexpected answers that showcase a feature in JMP like that. I'm a bit surprised for-each is faster than for, at some size. I like knowing that too.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I would not try to avoid anything. I like your current plan for a discussion, rather than a clear winner. Here are some discussion starter ideas:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;UL&gt;&lt;LI&gt;If you had N lists to convert, and they all had M elements, how do N and M affect the code you would write? Consider not just speed, but correctness and ease of maintenance.&lt;/LI&gt;&lt;LI&gt;Which ideas seem best for memory constrained machines?&lt;/LI&gt;&lt;LI&gt;How would you show "NaN" rather than "."?&lt;/LI&gt;&lt;LI&gt;What would a general purpose routine look like? What would you call it if it was built in to JMP?&lt;/LI&gt;&lt;/UL&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 21 Apr 2021 16:13:33 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/How-to-convert-a-numeric-list-into-a-character-one/m-p/378752#M62857</guid>
      <dc:creator>Craige_Hales</dc:creator>
      <dc:date>2021-04-21T16:13:33Z</dc:date>
    </item>
  </channel>
</rss>

