Difference between revisions of "Concat"

(WebinarArchive to subdomain)
 
(11 intermediate revisions by one other user not shown)
Line 5: Line 5:
 
Returns an array containing the elements of array «a» concatenated to the elements of array «b». Thus the number of items in the result is the sum of the number of items in  «a» and the number of items in  «b» .  The parameter «i» is an index  for array «a», «j» is an index for array «b» and «k» indexes the resulting array. The index parameters can be omitted if «a» and «b» are indexed implicitly, i.e. if they are single numbers or lists (1-D arrays), share an index or use [[Local Indexes|local indexes]].
 
Returns an array containing the elements of array «a» concatenated to the elements of array «b». Thus the number of items in the result is the sum of the number of items in  «a» and the number of items in  «b» .  The parameter «i» is an index  for array «a», «j» is an index for array «b» and «k» indexes the resulting array. The index parameters can be omitted if «a» and «b» are indexed implicitly, i.e. if they are single numbers or lists (1-D arrays), share an index or use [[Local Indexes|local indexes]].
  
When '''A''' and '''B''' are lists ,  
+
When '''A''' and '''B''' are lists , <code>Concat(A, B)</code> returns a list consisting of their elements.  This form is useful to concatenate (append, combine, join) two indexes to generate a third index.
Concat(A, B)
 
returns a list consisting of their elements.  This form is useful to concatenate two indexes to generate a third index.
 
  
When '''A''' and '''B''' are 1-D arrays with a common index
+
When '''A''' and '''B''' are 1-D arrays with a common index <code>Concat([A], [B])</code> returns a 2-D array with two columns.  Notice the square brackets around each variable.  If only two parameters are used, column index is '''.K'''.   
Concat([A], [B])
+
 
returns a 2-D array with two columns.  Notice the square brackets around each variable.  If only two parameters are used, column index is '''.K'''.   
+
==Example==
 +
Let:
 +
:<code>Index In1&nbsp;:= ['a', 'b', 'c']</code>
 +
 
 +
Then:
 +
:<code>Concat(In1, ['z'])  &rarr; ['a', 'b', 'c', 'z']</code>
  
 
==Optional Parameters==
 
==Optional Parameters==
When '''A''' is an array with index '''I''' and '''B''' is an array with index '''J''',   
+
When '''A''' is an array with index '''I''' and '''B''' is an array with index '''J''',  <code>Concat(A, B, I, J)</code>
Concat(A, B, I, J)
 
 
concatenates (i.e., joins) arrays '''A''' and '''B''', with the new result indexed by local index '''.K'''  whose values are the concatenation of '''I''' and '''J'''.
 
concatenates (i.e., joins) arrays '''A''' and '''B''', with the new result indexed by local index '''.K'''  whose values are the concatenation of '''I''' and '''J'''.
  
Alternatively, you can provide the index '''K''' for the result, whose length must be the sum of the lengths of '''I''' and '''J''':  
+
Alternatively, you can provide the index '''K''' for the result, whose length must be the sum of the lengths of '''I''' and '''J''': <code>Concat(A, B, I, J, K)</code>.
Concat(A, B, I, J, K)
+
 
 
When using this five parameter form, the index values of '''I''' and '''J''' are ignored --  so it doesn't matter if the elements of '''K''' are also elements of '''I''' or '''J'''. All that matters is that the number of elements in '''K''' is the number of elements of '''I''' plus the number of elements in '''J'''.  The positional ordering of the slices of each array are not altered -- the result consists of all the elements of '''A''' followed by all the elements of '''B'''.  
 
When using this five parameter form, the index values of '''I''' and '''J''' are ignored --  so it doesn't matter if the elements of '''K''' are also elements of '''I''' or '''J'''. All that matters is that the number of elements in '''K''' is the number of elements of '''I''' plus the number of elements in '''J'''.  The positional ordering of the slices of each array are not altered -- the result consists of all the elements of '''A''' followed by all the elements of '''B'''.  
  
 +
== Details & More Examples  ==
 
When '''A''' (or '''B''') is implicitly indexed (for example, if it is a list or a single number), you can omit the index parameter.  For example:
 
When '''A''' (or '''B''') is implicitly indexed (for example, if it is a list or a single number), you can omit the index parameter.  For example:
Concat([0], B, , J)
+
<code>Concat([0], B, , J)</code> prepends a column of zeroes to '''B'''.
prepends a column of zeroes to '''B'''.
 
 
 
 
 
== Details & More Examples  ==
 
  
 
=== Example 1===
 
=== Example 1===
 +
Let:
 +
:<code>Index I := [1, 2];</code>
 +
:<code>Index J := ['a', 'b'];</code>
 +
:<code>Index K := Concat(J, 'c');</code>
 +
:<code>Variable A := Array(I, J, 1);</code>
 +
:<code>Variable B := Array(I, 2);</code>
 +
 +
Then:
 +
:<code>Concat(A, [B], J, , K) &rarr;</code>
 +
:{| class="wikitable"
 +
!
 +
! colspan="3" |K  &#9654;
 +
|-
 +
! I &#9660;'''
 +
!'a'
 +
!'b'
 +
!'c'
 +
|-
 +
!1
 +
|1
 +
|1
 +
|2
 +
|-
 +
!2
 +
|1
 +
|1
 +
|2
 +
|}
  
 
=== Example 2 ===
 
=== Example 2 ===
Index Year1 := 2006 .. 2008
+
Let:
Index Years2 := 2009 .. 2010
+
:<code>Index Year1 := 2006 .. 2008</code>
Index YearsAll := Concat(Years1, Years2)  
+
:<code>Index Years2 := 2009 .. 2010</code>
YearsAll &rarr; [2006, 2007, 2008, 2009, 2010]
+
:<code>Index YearsAll := Concat(Years1, Years2)</code>
 
 
Index In1&nbsp;:= ['a', 'b', 'c']
 
Concat(In1, ['z'])  ['a', 'b', 'c', 'z']
 
 
 
INDEX I&nbsp;:= [1, 2];
 
INDEX J&nbsp;:= ['a', 'b'];
 
INDEX K&nbsp;:= Concat(J, 'c');
 
VAR A&nbsp;:= Array(I, J, 1);
 
VAR B&nbsp;:= Array(I, 2);
 
Concat(A, [B], J, , K)
 
 
Result:
 
    a  b  c
 
1| [1, 1, 2
 
2|  1, 1, 2]
 
  
 +
Then:
 +
:<code>YearsAll &rarr; [2006, 2007, 2008, 2009, 2010]</code>
 +
 
 
== See Also ==
 
== See Also ==
 +
* [[Arrays and Indexes]]
 +
* [[Array functions]]
 
* [[ConcatRows]]
 
* [[ConcatRows]]
 
* [[ConcatN]]
 
* [[ConcatN]]
 +
* [[Text Concatenation Operator: &]]
 +
* [[media:Concatenation.ana|Concatenation.ana]]
 +
*  [[media:Array_Concatenation.ana|Array Concatenation.ana]]
 +
* [http://WebinarArchive.analytica.com/2009-06-25-Array-Concatenation.wmv Array Concatenation.wmv] (a video recording of a webinar)

Latest revision as of 22:03, 6 November 2019


Concat(a, b, i, j, k)

Returns an array containing the elements of array «a» concatenated to the elements of array «b». Thus the number of items in the result is the sum of the number of items in «a» and the number of items in «b» . The parameter «i» is an index for array «a», «j» is an index for array «b» and «k» indexes the resulting array. The index parameters can be omitted if «a» and «b» are indexed implicitly, i.e. if they are single numbers or lists (1-D arrays), share an index or use local indexes.

When A and B are lists , Concat(A, B) returns a list consisting of their elements. This form is useful to concatenate (append, combine, join) two indexes to generate a third index.

When A and B are 1-D arrays with a common index Concat([A], [B]) returns a 2-D array with two columns. Notice the square brackets around each variable. If only two parameters are used, column index is .K.

Example

Let:

Index In1 := ['a', 'b', 'c']

Then:

Concat(In1, ['z']) → ['a', 'b', 'c', 'z']

Optional Parameters

When A is an array with index I and B is an array with index J, Concat(A, B, I, J) concatenates (i.e., joins) arrays A and B, with the new result indexed by local index .K whose values are the concatenation of I and J.

Alternatively, you can provide the index K for the result, whose length must be the sum of the lengths of I and J: Concat(A, B, I, J, K).

When using this five parameter form, the index values of I and J are ignored -- so it doesn't matter if the elements of K are also elements of I or J. All that matters is that the number of elements in K is the number of elements of I plus the number of elements in J. The positional ordering of the slices of each array are not altered -- the result consists of all the elements of A followed by all the elements of B.

Details & More Examples

When A (or B) is implicitly indexed (for example, if it is a list or a single number), you can omit the index parameter. For example: Concat([0], B, , J) prepends a column of zeroes to B.

Example 1

Let:

Index I := [1, 2];
Index J := ['a', 'b'];
Index K := Concat(J, 'c');
Variable A := Array(I, J, 1);
Variable B := Array(I, 2);

Then:

Concat(A, [B], J, , K) →
K ▶
I ▼ 'a' 'b' 'c'
1 1 1 2
2 1 1 2

Example 2

Let:

Index Year1 := 2006 .. 2008
Index Years2 := 2009 .. 2010
Index YearsAll := Concat(Years1, Years2)

Then:

YearsAll → [2006, 2007, 2008, 2009, 2010]

See Also

Comments


You are not allowed to post comments.