Search icon CANCEL
Subscription
0
Cart icon
Your Cart (0 item)
Close icon
You have no products in your basket yet
Save more on your purchases! discount-offer-chevron-icon
Savings automatically calculated. No voucher code required.
Arrow left icon
All Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Newsletter Hub
Free Learning
Arrow right icon
timer SALE ENDS IN
0 Days
:
00 Hours
:
00 Minutes
:
00 Seconds
Arrow up icon
GO TO TOP
Modern R Programming Cookbook

You're reading from   Modern R Programming Cookbook Recipes to simplify your statistical applications

Arrow left icon
Product type Paperback
Published in Oct 2017
Publisher Packt
ISBN-13 9781787129054
Length 236 pages
Edition 1st Edition
Languages
Arrow right icon
Author (1):
Arrow left icon
Jaynal Abedin Jaynal Abedin
Author Profile Icon Jaynal Abedin
Jaynal Abedin
Arrow right icon
View More author details
Toc

Table of Contents (16) Chapters Close

Title Page
Credits
About the Author
About the Reviewer
www.PacktPub.com
Customer Feedback
Preface
1. Installing and Configuring R and its Libraries FREE CHAPTER 2. Data Structures in R 3. Writing Customized Functions 4. Conditional and Iterative Operations 5. R Objects and Classes 6. Querying, Filtering, and Summarizing 7. R for Text Processing 8. R and Databases 9. Parallel Processing in R

Writing a function using the switch operator


While writing a program, you might encounter a situation where you have to pick an item from a list based on a certain value of a test condition. The switch operator or the switch function in R is very handy in this type of situation. In this recipe, you will learn how to write R using the switch function.

Getting ready

Suppose you are working on a problem where you have a series of numeric variables and your task is to produce the most appropriate summary statistics for all of them. If the distribution is symmetric, then you will produce the mean and standard deviation. However, if the distribution is not symmetric, then your task is to calculate the median and MAD. In this type of situation, the use of the switch operator comes into play. To execute the whole task, there is a part where you will test whether the distribution is symmetric or not. Let’s say you have defined a variable sym. This variable will take a value 1 if the distribution is...

lock icon The rest of the chapter is locked
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at ₹800/month. Cancel anytime
Banner background image