- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Get Direct Link
- Report Inappropriate Content
List of Strings
To create a matrix of N identical numbers, I can use J(N, 1, number).
What is the shortest (syntax) and fastest way to create a list of N identical strings?
Accepted Solutions
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Get Direct Link
- Report Inappropriate Content
Re: List of Strings
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Get Direct Link
- Report Inappropriate Content
Re: List of Strings
Repeat({"A"}, 1000)
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Get Direct Link
- Report Inappropriate Content
Re: List of Strings
: )
Scripting Index -> Online Help -> Scripting Guide:
https://www.jmp.com/support/help/en/18.0/#page/jmp/repeat-function.shtml#ww270242
I fear a LLM will have its difficulties with such cool hidden features ...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Get Direct Link
- Report Inappropriate Content
Re: List of Strings
I'm not really sure if there is anything hidden about Repeat()? Of course, you have to know about it, but you will come across it fairly quickly in scripting index. But you might need a bit of luck as the function group which it belongs to is Character and not Character, Matrix and List which it should be but it isn't the only one like this.
You can also go with a bit more "normal" route where replace all values in a list
Names Default To Here(1);
l = As List(J(1000, 1, .));
l[1::N Items(l)] = "A";
show(l);
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Get Direct Link
- Report Inappropriate Content
Re: List of Strings
It's easy to find Repeat, but it's more difficult to find and understand the correct syntax to generate the list.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Get Direct Link
- Report Inappropriate Content
Re: List of Strings
Both scripting index and Scripting Guide provide an example for that
Function description also tells quite accurately what Repeat() does but it does require some extra understanding on how concatenation of lists in JMP works. Luckily JSL Syntax Reference at least offers link to Scripting Guide which has much better documentation of the function
Also one more method is to use Substitute (Repeat() is what I would use in simple case like this)
Names Default To Here(1);
l = Substitute(As List(J(1000, 1, 1)), 1, "A");
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Get Direct Link
- Report Inappropriate Content
Re: List of Strings
Yes, see https://community.jmp.com/t5/Discussions/List-of-Strings/m-p/806737/highlight/true#M98527
I agree, it's very well described in the Scripting Guide. Interesting that the LLM did not find / use (?) this information.
From the Scripting Index and the JSL syntax reference it's not possible to get this detail.
[Scripting Index: ... without executing the code - and interpreting the result].
Some comments / details will help the users - and the LLM.
Once the documentation can be found and understood by a LLM, JSL coding will be like heaven : )
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Get Direct Link
- Report Inappropriate Content
Re: List of Strings
Scripting Index and JSL Syntax reference both do contain this information?
- Scripting Index
-
Returns the text, matrix, or list specified by the x argument concatenated with itself n times.
-
- JSL Syntax Reference
- Returns a copy of source concatenated with itself a times
You might have to read it a bit in reverse, as you might not (initially) consider your input as a list but your output is. You also might have to take a look into list concatenation Character Functions (jmp.com) (once again should be also found under list and matrix)
Also one more option for simple cases is to utilize Repeat with a string and then use Words to break it into a list
Names Default To Here(1);
l = Words(Repeat("A", 1000), "");