How it works…

The switch function takes an integer value input as statement and then returns an item from the list based on the value of the input statement. In the example implemented in this recipe, the list contains two elements. The two elements are two functions to calculate the summary statistics of a given numeric variables. The switch(statement, list) statement takes the input through the sym variable. If the value of sym is 1, then the switch function will return the first element from the item list, and it will return the second element if the value of sym is 2.

Since the item in the list is a function, to calculate actual summary statistics, you have to call the resultant function as it has been done.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset