Replaces the contents of the result variable with the elements from the input data vector in the order given by the input position vector. The input vector is left unchanged. The elements of the input data vector are numbered starting with one, i.e., the first element of the input data vector is element number one. You will get a runtime error if the input position vector element points to a non-existent position of the input data vector. For example, if the input data vector had only 5 elements, and one of the elements of the input position vector calls for element number 6, you will get a runtime error message and the program will abort. TAKE is usually used with SHUFFLE to simulate sampling without replacement. The TAKE command is the complement, or inverse, of the REMOVE command.
|
COPY (12 8 10 4 6 2) data TAKE data (1 3 5) selectedData PRINT selectedData The above program produces the following output: selectedData: (12.0, 10.0, 6.0) Here is a more practical example: 'What is the probability of getting 'exactly one ace of any suit in 'a 5-card hand? COPY 1,13 1,13 1,13 1,13 deck COPY 10000 trials COPY 0 successCount REPEAT trials SHUFFLE deck shuffledDeck TAKE shuffledDeck 1,5 hand COUNT hand = 1 aceCount IF aceCount = 1 ADD 1 successCount successCount END END DIVIDE successCount trials prob PRINT prob The above program produced the following result: prob: 0.2986 |