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…

In the first step, you should create the source variable to apply the conditional operation and then calculate the cut-off median for this recipe. Once you have the source variable and the cut-off value, you can pass the conditional operator > inside the ifelse function. The ifelse function takes the source variable as input and a cut-off with conditional operator. In this recipe, the conditional operator is a greater than operator >. If the value of the variable x is greater than the median of x, then the new variable newX will get a value 1; otherwise, it will get 0. The ifelse function works in a vector of input, and it does not require any repetition or loop. Only the single line of code can perform the operation for the ...

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