|
<< Click to Display Table of Contents >> Manual > Screen Creation Guide > Script > Script Example > Script Tips > Extracting Data from an Array |
Extracting Data from an Array
The FA-Panel script array has a variety of index specification methods. In addition to simple subscript specification such as "A[0]", data extraction is possible using range specification and comparison conditions.
Here we will introduce some typical extraction examples (they can also be used as multidimensional arrays).
|
For usage other than the sequence extraction examples introduced here, please refer to "Arrays". |
•Index Range
You can extract data within a specified range by specifying a range in the subscript with a single colon ":" (note that subscripts are numbers starting from 0).
var vT_a = c(1, 2, 3, 4, 5); // Store the values 1 through 5 consecutively in the array from vT_a[0] to vT_a[4] var vT_b = vT_a[ 1:3 ]; // 2, 3, and 4 are stored in vT_b[0] through vT_b[2] |
•Extraction by Boolean Conditions
If you pass an array of Booleans equal to the number of elements in the
array, you can extract only the elements that are True.
var vT_a = c(1, 2, 3, 4, 5); var vT_b = vT_a[c(T, F, T, F, T)]; // 1, 3, and 5 are stored in vT_b[0] to vT_b[2] |
For example, if the extraction conditions are complex, you can create a separate function for checking the position of the element you want to extract, and then use the Boolean array obtained by the function to extract the element from the array.
•Extraction by comparison conditions 1
By specifying a comparison condition for array elements, you can extract only the data that matches the condition.
var vT_a = c(1, 2, 3, 4, 5); var vT_b = vT_a[ vT_a < 4 ]; // 1, 2, 3 are stored in vT_b[0] to vT_b[2] |
•Extraction by comparison conditions 2
For example, in an array that contains unspecified strings, you can retrieve only the elements other than zero-length strings (""). By specifying a comparison condition for the array elements, you can extract only the data that matches the condition.
var vT_a = c(“AAA”, “”, “”, “BBB”, “CCC”); var vT_b = vT_a[ vT_a != “” ]; // “AAA”, “BBB”, and “CCC” are stored in vT_b[0] to vT_b[2] |