Skip to Content
Modern R Programming Cookbook
book

Modern R Programming Cookbook

by Jaynal Abedin
October 2017
Beginner to intermediate
236 pages
7h 38m
English
Packt Publishing
Content preview from Modern R Programming Cookbook

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.

Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

R Cookbook, 2nd Edition

R Cookbook, 2nd Edition

JD Long, Paul Teetor

Publisher Resources

ISBN: 9781787129054Supplemental Content